From aa0de90361096e93100c7f9577819d653e91e8fe Mon Sep 17 00:00:00 2001 From: Mattrixwv Date: Fri, 14 Aug 2020 18:41:47 -0400 Subject: [PATCH] Initial commit with a few examples --- .gitignore | 2 ++ HelloWorld.cs | 19 +++++++++++++++++++ Lists.cs | 27 ++++++++++++++++++++++++++ Numbers.cs | 44 +++++++++++++++++++++++++++++++++++++++++++ StringManipulation.cs | 41 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 133 insertions(+) create mode 100644 .gitignore create mode 100644 HelloWorld.cs create mode 100644 Lists.cs create mode 100644 Numbers.cs create mode 100644 StringManipulation.cs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..43006e6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +#Ignore all executables +*.exe \ No newline at end of file diff --git a/HelloWorld.cs b/HelloWorld.cs new file mode 100644 index 0000000..ea0c7a8 --- /dev/null +++ b/HelloWorld.cs @@ -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"); + } + } +} \ No newline at end of file diff --git a/Lists.cs b/Lists.cs new file mode 100644 index 0000000..de35953 --- /dev/null +++ b/Lists.cs @@ -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 names = new List { "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}"); + } + } +} \ No newline at end of file diff --git a/Numbers.cs b/Numbers.cs new file mode 100644 index 0000000..c28ebc1 --- /dev/null +++ b/Numbers.cs @@ -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}"); + } + } +} \ No newline at end of file diff --git a/StringManipulation.cs b/StringManipulation.cs new file mode 100644 index 0000000..3a1188e --- /dev/null +++ b/StringManipulation.cs @@ -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()); + } + } +} \ No newline at end of file