diff --git a/Session02/Excample02/Program.cs b/Session02/Excample02/Program.cs new file mode 100644 index 0000000..ebb556a --- /dev/null +++ b/Session02/Excample02/Program.cs @@ -0,0 +1,31 @@ +using System; +using System.Runtime.CompilerServices; + +namespace Excample02 +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("Do you want to enter your name? (y/n)"); + var key = Console.ReadKey(); + + if (key.KeyChar == 'n') + return; + + else if (key.KeyChar == 'y') + { + Console.WriteLine("\nEnter your name: "); + var name = Console.ReadLine(); + + Console.WriteLine($"Hello, {name}"); + } + else + { + Console.WriteLine("\nI don't understand?"); + } + Console.WriteLine("Press any key to exit program..."); + Console.ReadKey(true); + } + } +} diff --git a/Session02/Excample02/Session02exercise02.csproj b/Session02/Excample02/Session02exercise02.csproj new file mode 100644 index 0000000..c73e0d1 --- /dev/null +++ b/Session02/Excample02/Session02exercise02.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp3.1 + + + diff --git a/Session02/Session02.sln b/Session02/Session02.sln new file mode 100644 index 0000000..d0032a3 --- /dev/null +++ b/Session02/Session02.sln @@ -0,0 +1,43 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30413.136 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Session02Exercise01", "Session02Exercise01\Session02Exercise01.csproj", "{5781BFBB-1E01-47F7-A1DE-5BD53D78E140}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Session02exercise02", "Excample02\Session02exercise02.csproj", "{6B5DA0D0-23A1-47A2-B34F-A0A125A584FD}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Session02Excersise03", "Session02Excersise03\Session02Excersise03.csproj", "{4309C8FA-CF78-44EB-9535-36703D508250}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Session02Excersise04", "Session02Excersise04\Session02Excersise04.csproj", "{85B305B6-E306-4951-ADE5-01656F70DA96}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5781BFBB-1E01-47F7-A1DE-5BD53D78E140}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5781BFBB-1E01-47F7-A1DE-5BD53D78E140}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5781BFBB-1E01-47F7-A1DE-5BD53D78E140}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5781BFBB-1E01-47F7-A1DE-5BD53D78E140}.Release|Any CPU.Build.0 = Release|Any CPU + {6B5DA0D0-23A1-47A2-B34F-A0A125A584FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6B5DA0D0-23A1-47A2-B34F-A0A125A584FD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6B5DA0D0-23A1-47A2-B34F-A0A125A584FD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6B5DA0D0-23A1-47A2-B34F-A0A125A584FD}.Release|Any CPU.Build.0 = Release|Any CPU + {4309C8FA-CF78-44EB-9535-36703D508250}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4309C8FA-CF78-44EB-9535-36703D508250}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4309C8FA-CF78-44EB-9535-36703D508250}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4309C8FA-CF78-44EB-9535-36703D508250}.Release|Any CPU.Build.0 = Release|Any CPU + {85B305B6-E306-4951-ADE5-01656F70DA96}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {85B305B6-E306-4951-ADE5-01656F70DA96}.Debug|Any CPU.Build.0 = Debug|Any CPU + {85B305B6-E306-4951-ADE5-01656F70DA96}.Release|Any CPU.ActiveCfg = Release|Any CPU + {85B305B6-E306-4951-ADE5-01656F70DA96}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {B8AA34BE-8E82-4BCB-85BD-2689F1C50616} + EndGlobalSection +EndGlobal diff --git a/Session02/Session02Excersise03/Program.cs b/Session02/Session02Excersise03/Program.cs new file mode 100644 index 0000000..0c9fdf2 --- /dev/null +++ b/Session02/Session02Excersise03/Program.cs @@ -0,0 +1,81 @@ +using System; +using System.Net.WebSockets; + +namespace Session02Excersise03 +{ + class Program + { + static void Main(string[] args) + { + //Binary operation + var additionResult = 1 + 2; + Console.WriteLine($"Addition result {additionResult}"); + + var incrementResult = ++additionResult; + Console.WriteLine($"Increment result {incrementResult}"); + + var trueValue = true; + + var falseValue = false; + + // Bitwise operationer + var andResult = 0b0010 & 0b0100; //0b0110; + var orResult = 0b0001 | 0b0001; //0b0001; + var xorResult = 0b0001 ^ 0b0001; //0b0000; + + Console.WriteLine($"and result {andResult}"); + Console.WriteLine($"or result {orResult}"); + Console.WriteLine($"xor result {xorResult}"); + + var modulResult = 3 % 2; + Console.WriteLine($"modul result {modulResult}"); + + var highInteger = 1000; + var integerDivisionResult = highInteger / 3; + var doubleDivissionResult = highInteger / 3.0; + + Console.WriteLine($"integer division result {integerDivisionResult}"); + Console.WriteLine($"double division result {doubleDivissionResult}"); + + //implicit värdekonvertering till double + var forcedIntDivisionResult = (int)(highInteger / 3.0); + Console.WriteLine($"forced int division result {forcedIntDivisionResult}"); + + var conversionResult = Convert.ToInt32(doubleDivissionResult); + + Console.WriteLine($"Conversion result {conversionResult}"); + + var midpointDivisionResult = 10.0 / 3.0; + + Console.WriteLine($"Midpoint division result {midpointDivisionResult}"); + Console.WriteLine($"castToInt" + ((int)midpointDivisionResult).ToString()); + Console.WriteLine($"ceiling " + Math.Ceiling(midpointDivisionResult)); + Console.WriteLine($"floor " + Math.Floor(midpointDivisionResult)); + Console.WriteLine($"ceiling " + Math.Round(midpointDivisionResult)); + + //T + additionResult += 2; //Samma som (additionalResult = additionalResult + 2) + additionResult -= 2; + additionResult *= 2; + additionResult /= 2; + + //Boelska jämförelseoperatorer + var greaterThanResult = 5 > 3; + var lessThanResult = 5 < 3; + var greaterOrEqual = 5 >= 5; + var lessOrEqual = 3 <= 5; + + Console.WriteLine($"greaterThanResult {greaterThanResult}"); + Console.WriteLine($"lessThanResult {lessThanResult}"); + Console.WriteLine($"greater or Equal {greaterOrEqual}"); + Console.WriteLine($"less or equal {lessOrEqual}"); + + var andOperationsResult = true && false; + var orOperationResult = false || true; + + Console.WriteLine($"And operations Result {andOperationsResult}"); + Console.WriteLine($"Or operations Result {orOperationResult}"); + Console.ReadKey(true); + } + } +} diff --git a/Session02/Session02Excersise03/Session02Excersise03.csproj b/Session02/Session02Excersise03/Session02Excersise03.csproj new file mode 100644 index 0000000..c73e0d1 --- /dev/null +++ b/Session02/Session02Excersise03/Session02Excersise03.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp3.1 + + + diff --git a/Session02/Session02Excersise04/Program.cs b/Session02/Session02Excersise04/Program.cs new file mode 100644 index 0000000..194b989 --- /dev/null +++ b/Session02/Session02Excersise04/Program.cs @@ -0,0 +1,40 @@ +using System; + +namespace Session02Excersise04 +{ + class Program + { + static void Main(string[] args) + { + //Console.WriteLine("Ange ålder: "); + + //var input = Console.ReadLine(); + //var integer = Convert.ToInt32(input); + + //if (integer >= 18) + //{ + // Console.WriteLine("Du får köpa tobaksprodukter."); + //} + //else + //{ + // Console.WriteLine("Du får inte köpa tobak! "); + //} + + //if (integer >= 40) + //{ + // Console.WriteLine("Men du är för gammal för att röka!"); + //} + + Console.WriteLine("Ange en badtemperatur i grader C: "); + + var input = Console.ReadLine(); + var integer = Convert.ToInt32(input); + + string waterLabel = integer >= 27 ? "Det går bra att bada" : "Det går inte att bada"; + Console.WriteLine($"{waterLabel} i havet!"); + + Console.WriteLine("Tryck på valfri tangent för att avsluta..."); + Console.ReadKey(true); + } + } +} diff --git a/Session02/Session02Excersise04/Session02Excersise04.csproj b/Session02/Session02Excersise04/Session02Excersise04.csproj new file mode 100644 index 0000000..c73e0d1 --- /dev/null +++ b/Session02/Session02Excersise04/Session02Excersise04.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp3.1 + + + diff --git a/Session02/Session02Exercise01/Program.cs b/Session02/Session02Exercise01/Program.cs new file mode 100644 index 0000000..bb65bdb --- /dev/null +++ b/Session02/Session02Exercise01/Program.cs @@ -0,0 +1,18 @@ +using System; + +namespace Session02Exercise01 +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("Hello world!"); + var integer = 0; + Console.WriteLine("integer is" + integer.ToString()); + + string stringValue = "My string is cool!"; + + Console.WriteLine($"The string value of stringValie is {stringValue}"); + } + } +} diff --git a/Session02/Session02Exercise01/Session02Exercise01.csproj b/Session02/Session02Exercise01/Session02Exercise01.csproj new file mode 100644 index 0000000..c73e0d1 --- /dev/null +++ b/Session02/Session02Exercise01/Session02Exercise01.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp3.1 + + + diff --git a/Session03/Session03.sln b/Session03/Session03.sln new file mode 100644 index 0000000..240772e --- /dev/null +++ b/Session03/Session03.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30413.136 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Session03Exersise01", "Session03Exersise01\Session03Exersise01.csproj", "{9C90BA88-D314-4C64-8D2C-BDE6CA882C1E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9C90BA88-D314-4C64-8D2C-BDE6CA882C1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9C90BA88-D314-4C64-8D2C-BDE6CA882C1E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9C90BA88-D314-4C64-8D2C-BDE6CA882C1E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9C90BA88-D314-4C64-8D2C-BDE6CA882C1E}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {DAB41CAE-214D-40AB-BD39-8D5A82665136} + EndGlobalSection +EndGlobal diff --git a/Session03/Session03Exersise01/Program.cs b/Session03/Session03Exersise01/Program.cs new file mode 100644 index 0000000..75efa1f --- /dev/null +++ b/Session03/Session03Exersise01/Program.cs @@ -0,0 +1,92 @@ +using System; +using System.Globalization; +using System.Linq; + +namespace Session03Exersise01 +{ + class Program + { + static void Main(string[] args) + { + double doubleMid = 0; + double dblSum = 0; + int intParsedOk = 0; + + Console.WriteLine("Ange ett antal siffror, separerat med kommatecken"); + var input = Console.ReadLine(); + var inputArray = input.Split(",", StringSplitOptions.RemoveEmptyEntries); + double?[] numberArray = new double?[inputArray.Length]; + + for (int i = 0; i < inputArray.Length; i++) + { + bool parsed; + + try + { + numberArray[i] = Convert.ToDouble(inputArray[i]); + parsed = true; + intParsedOk++; + } + + catch (Exception) + { + numberArray[i] = 0; + parsed = false; + } + + if (parsed == false) + { + continue; + } + + dblSum += numberArray[i].Value; + } + doubleMid = dblSum / intParsedOk; + + + Console.WriteLine($"Min value is: {numberArray.Min()} Maxvalue is: {numberArray.Max()} Total value is: {dblSum} Midvalue is: {doubleMid :f2}"); + + Console.WriteLine("\nPress any key to quit program..."); + Console.ReadKey(true); + + //for (int i = 0; i < inputArray.Length; i++) + //{ + // NumberStyles numberStyle = NumberStyles.Integer | NumberStyles.Float; //Bestämmer vilken typ man vill parsa till! + // IFormatProvider formatProvider = new CultureInfo("sv-SE"); //CultureInfo.InvariantCulture; + // IFormatProvider currentNulture = CultureInfo.CurrentCulture;*/ + + // bool parsed = double.TryParse(inputArray[i], out double parsedValue); + + + + //if (parsed == true) + //{ + // numberArray[i] = parsedValue; + //} + //else + //{ + // numberArray[i] = null; + //} + } + + //static double GetDoubleValue(string input) + //{ + // try + // { + // //numberArray[i] = Convert.ToDouble(inputArray[i]); + // var result = int.Parse(input); + // return result; + // } + // catch (FormatException ex) + // { + // return double.MinValue; + + // throw ex; + // } + // catch (Exception ex) + // { + // return 0; + // } + //} + } +} diff --git a/Session03/Session03Exersise01/Session03Exersise01.csproj b/Session03/Session03Exersise01/Session03Exersise01.csproj new file mode 100644 index 0000000..c73e0d1 --- /dev/null +++ b/Session03/Session03Exersise01/Session03Exersise01.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp3.1 + + +