Initial commit with a few examples

This commit is contained in:
2020-08-14 18:41:47 -04:00
commit aa0de90361
5 changed files with 133 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
#Ignore all executables
*.exe

19
HelloWorld.cs Normal file
View File

@@ -0,0 +1,19 @@
//C#/Tutorials/HelloWorld.cs
//Matthew Ellison
// Created: 07-29-20
//Modified: 07-29-20
//This is a simple hello world program
using System;
namespace mee{
public class HelloWorld{
static void Main(string[] args){
Console.WriteLine("Hello World");
string testString = "World";
Console.WriteLine($"Hello {testString} 2");
}
}
}

27
Lists.cs Normal file
View File

@@ -0,0 +1,27 @@
//C#/Tutorials/HelloWorld.cs
//Matthew Ellison
// Created: 07-29-20
//Modified: 07-29-20
//This shows some basic list operations
using System;
namespace mee{
public class Lists{
public static Main(string[] args){
List<string> names = new List<string> { "Matthew", "Ana", "Felipe", "Maria", "Bill"};
names.Remove("Ana");
names.Add("Felipe");
foreach(string name in names){
Console.WriteLine($"{name}");
}
int location = names.IndexOf("Felipe");
Console.WriteLine($"location = {location}");
location = names.IndexOf("Bob");
Console.WriteLine($"location = {location}");
Console.WriteLine($"size = {names.Count}");
}
}
}

44
Numbers.cs Normal file
View File

@@ -0,0 +1,44 @@
//C#/Tutorials/Numbers.cs
//Matthew Ellison
// Created: 07-29-20
//Modified: 07-29-20
//This is a simple hello world program
using System;
namespace mee{
public class Numbers{
public static void Main(string[] args){
int i1 = 1;
int i2 = 2;
int i3 = 3;
int div = i3/i2;
Console.WriteLine($"3/2i = {div}\n");
float f1 = 1.0F;
float f3 = 3.0F;
float fDiv = f1/f3;
double a = 1.0;
double b = 3.0;
double c = a / b;
//Decimal has a smaller range, but a greater precision than double
decimal d = 1.0M;
decimal e = 3.0M;
decimal f = d / e;
Console.WriteLine($"Float: {Single.MinValue} - {Single.MaxValue}");
Console.WriteLine($"Double: {Double.MinValue} - {Double.MaxValue}");
Console.WriteLine($"Decimal: {Decimal.MinValue} - {Decimal.MaxValue}");
Console.WriteLine($"1/3F = {fDiv}");
Console.WriteLine($"1/3D = {c}");
Console.WriteLine($"1/3M = {f}\n");
double answer = Math.Pow(2.50, 2) * Math.PI;
Console.WriteLine($"area = {answer}");
}
}
}

41
StringManipulation.cs Normal file
View File

@@ -0,0 +1,41 @@
//C#/Tutorials/StringManipulation.cs
//Matthew Ellison
// Created: 07-29-20
//Modified: 07-29-20
//This has some simple string manipulation examples
using System;
namespace mee{
public class StringManipulation{
public static void Main(string[] args){
string greeting = " Hello World ";
Console.WriteLine($"[{greeting}]");
string trimmedGreeting = "";
//trimmedGreeting = greeting.TrimStart();
Console.WriteLine($"[{trimmedGreeting}]");
//trimmedGreeting = greeting.TrimEnd();
Console.WriteLine($"[{trimmedGreeting}]");
trimmedGreeting = greeting.Trim();
Console.WriteLine($"[{trimmedGreeting}]");
//Find
Console.WriteLine("\nFind:");
string songLyrics = "You say goodbye, and I say hello";
Console.WriteLine(songLyrics.Contains("goodbye"));
Console.WriteLine(songLyrics.Contains("greetings"));
Console.WriteLine(songLyrics.EndsWith("hello"));
Console.WriteLine(songLyrics.EndsWith("goodbye"));
//Find and replace
Console.WriteLine("\nFind and Replace:");
Console.WriteLine(greeting.Trim());
string newGreeting = greeting.Replace("Hello", "Greetings").Trim();
Console.WriteLine(newGreeting);
Console.WriteLine(newGreeting.ToLower());
Console.WriteLine(newGreeting.ToUpper());
}
}
}