From ddc33e2beb68eb3db44619f5f8aeda55e99727bd Mon Sep 17 00:00:00 2001 From: Geir Okkenhaug Jerstad Date: Thu, 14 Nov 2024 13:29:50 +0100 Subject: [PATCH] ifElse --- Emne 3/ConsoleApp3/ConsoleApp3/Program.cs | 18 ++++++++---- Emne 3/ConsoleApp4/ConsoleApp4.sln | 16 +++++++++++ Emne 3/ConsoleApp4/IfElse/IfElse.csproj | 10 +++++++ Emne 3/ConsoleApp4/IfElse/Program.cs | 34 +++++++++++++++++++++++ 4 files changed, 72 insertions(+), 6 deletions(-) create mode 100644 Emne 3/ConsoleApp4/ConsoleApp4.sln create mode 100644 Emne 3/ConsoleApp4/IfElse/IfElse.csproj create mode 100644 Emne 3/ConsoleApp4/IfElse/Program.cs diff --git a/Emne 3/ConsoleApp3/ConsoleApp3/Program.cs b/Emne 3/ConsoleApp3/ConsoleApp3/Program.cs index 32b4f7f..eaa490b 100644 --- a/Emne 3/ConsoleApp3/ConsoleApp3/Program.cs +++ b/Emne 3/ConsoleApp3/ConsoleApp3/Program.cs @@ -8,11 +8,11 @@ } public static decimal sum() - { - int a = 3; - decimal b = 5; - decimal sum = a + b; - return sum; + { + int a = 3; + decimal b = 5; + decimal sum = a + b; + return sum; } private static decimal Sum(decimal a, decimal b) @@ -20,10 +20,16 @@ return a + b; } + private static void ReturnNothing() + { + Console.WriteLine("Denne metoden returnerer ingenting"); + } + public static void Run() { Console.WriteLine(sum()); - Console.WriteLine(Sum(9,5)); + Console.WriteLine($"Summen av 9 og 5 er: {Sum(9,5)}"); + ReturnNothing(); } } } \ No newline at end of file diff --git a/Emne 3/ConsoleApp4/ConsoleApp4.sln b/Emne 3/ConsoleApp4/ConsoleApp4.sln new file mode 100644 index 0000000..b00b733 --- /dev/null +++ b/Emne 3/ConsoleApp4/ConsoleApp4.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IfElse", "IfElse\IfElse.csproj", "{ADAD2168-14E9-4D41-A651-74D0F952601F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {ADAD2168-14E9-4D41-A651-74D0F952601F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {ADAD2168-14E9-4D41-A651-74D0F952601F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {ADAD2168-14E9-4D41-A651-74D0F952601F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {ADAD2168-14E9-4D41-A651-74D0F952601F}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/Emne 3/ConsoleApp4/IfElse/IfElse.csproj b/Emne 3/ConsoleApp4/IfElse/IfElse.csproj new file mode 100644 index 0000000..2f4fc77 --- /dev/null +++ b/Emne 3/ConsoleApp4/IfElse/IfElse.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/Emne 3/ConsoleApp4/IfElse/Program.cs b/Emne 3/ConsoleApp4/IfElse/Program.cs new file mode 100644 index 0000000..db114ed --- /dev/null +++ b/Emne 3/ConsoleApp4/IfElse/Program.cs @@ -0,0 +1,34 @@ +namespace CompareApp +{ + class IsEqualOr + { + private static int num = 10; + private static int num2 = 10; + private static bool IsEqual = false; + static void Main(string[] args) + { + if (num == num2) + { + Console.WriteLine("Equal"); + IsEqual = true; + } + else + { + Console.WriteLine("Not Equal"); + IsEqual = false; + } + + if (IsEqual) + { + num++; + Console.WriteLine(num); + } + else + { + num--; + Console.WriteLine(num); + } + } + } +} +