From 558073a24d08187c400f8bea430e7a6e15a009c2 Mon Sep 17 00:00:00 2001 From: Geir Okkenhaug Jerstad Date: Mon, 25 Nov 2024 15:00:30 +0100 Subject: [PATCH] overloading --- .../OverloadOgDefault/OverloadOgDefault.sln | 16 +++++++++ .../OverloadOgDefault.csproj | 10 ++++++ .../OverloadOgDefault/Program.cs | 33 +++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 Emne 3/OverloadOgDefault/OverloadOgDefault.sln create mode 100644 Emne 3/OverloadOgDefault/OverloadOgDefault/OverloadOgDefault.csproj create mode 100644 Emne 3/OverloadOgDefault/OverloadOgDefault/Program.cs diff --git a/Emne 3/OverloadOgDefault/OverloadOgDefault.sln b/Emne 3/OverloadOgDefault/OverloadOgDefault.sln new file mode 100644 index 0000000..4d2518c --- /dev/null +++ b/Emne 3/OverloadOgDefault/OverloadOgDefault.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OverloadOgDefault", "OverloadOgDefault\OverloadOgDefault.csproj", "{1B403057-2541-4916-ACEC-75CEB5AA053C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1B403057-2541-4916-ACEC-75CEB5AA053C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1B403057-2541-4916-ACEC-75CEB5AA053C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1B403057-2541-4916-ACEC-75CEB5AA053C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1B403057-2541-4916-ACEC-75CEB5AA053C}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/Emne 3/OverloadOgDefault/OverloadOgDefault/OverloadOgDefault.csproj b/Emne 3/OverloadOgDefault/OverloadOgDefault/OverloadOgDefault.csproj new file mode 100644 index 0000000..2f4fc77 --- /dev/null +++ b/Emne 3/OverloadOgDefault/OverloadOgDefault/OverloadOgDefault.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/Emne 3/OverloadOgDefault/OverloadOgDefault/Program.cs b/Emne 3/OverloadOgDefault/OverloadOgDefault/Program.cs new file mode 100644 index 0000000..3290ba9 --- /dev/null +++ b/Emne 3/OverloadOgDefault/OverloadOgDefault/Program.cs @@ -0,0 +1,33 @@ +using System.Formats.Asn1; + +namespace OverloadOgDefault +{ + class Program + { + class OverloadExample + { + public int Add(int a, int b) + { + return a + b; + } + + public int Add(int a, int b, int c) + { + return a + b + c; + } + + public double Add(double a, double b) + { + return a + b; + } + } + static void Main(string[] args) + { + OverloadExample calculator = new OverloadExample(); + + Console.WriteLine("Sum med to int-parametre: " + calculator.Add(calculator.Add(calculator.Add(2,2),2), 3)); + Console.WriteLine("Sum med tre int-parametre: " + calculator.Add(2, 3, 9)); + Console.WriteLine("Sum med to double-parametere: {0}", calculator.Add(2.3, 3.9)); + } + } +} \ No newline at end of file