From 0aa442271fe49017d5b61511d28896867cdbcb33 Mon Sep 17 00:00:00 2001 From: Geir Okkenhaug Jerstad Date: Wed, 27 Nov 2024 09:43:48 +0100 Subject: [PATCH] Overload finally --- .../MiniOppgaveOverloads.sln | 10 +++++++ .../MiniOppgaveOverloads.csproj | 10 +++++++ .../MiniOppgaveOverloads/Program.cs | 10 +++++++ Emne 3/MiniOverloads/MiniOverloads.sln | 16 +++++++++++ .../MiniOverloads/MiniOverloads.csproj | 10 +++++++ Emne 3/MiniOverloads/MiniOverloads/Program.cs | 8 ++++++ .../MiniOverloads/WelcomeMessage.cs | 27 +++++++++++++++++++ .../MiniOverloadsOppgave.sln | 10 +++++++ .../MiniOverloadsOppgave.csproj | 10 +++++++ .../MiniOverloadsOppgave/Program.cs | 23 ++++++++++++++++ .../OverloadOgDefault/Program.cs | 18 +++++++++++-- 11 files changed, 150 insertions(+), 2 deletions(-) create mode 100644 Emne 3/MiniOppgaveOverloads/MiniOppgaveOverloads.sln create mode 100644 Emne 3/MiniOppgaveOverloads/MiniOppgaveOverloads/MiniOppgaveOverloads.csproj create mode 100644 Emne 3/MiniOppgaveOverloads/MiniOppgaveOverloads/Program.cs create mode 100644 Emne 3/MiniOverloads/MiniOverloads.sln create mode 100644 Emne 3/MiniOverloads/MiniOverloads/MiniOverloads.csproj create mode 100644 Emne 3/MiniOverloads/MiniOverloads/Program.cs create mode 100644 Emne 3/MiniOverloads/MiniOverloads/WelcomeMessage.cs create mode 100644 Emne 3/MiniOverloadsOppgave/MiniOverloadsOppgave.sln create mode 100644 Emne 3/MiniOverloadsOppgave/MiniOverloadsOppgave/MiniOverloadsOppgave.csproj create mode 100644 Emne 3/MiniOverloadsOppgave/MiniOverloadsOppgave/Program.cs diff --git a/Emne 3/MiniOppgaveOverloads/MiniOppgaveOverloads.sln b/Emne 3/MiniOppgaveOverloads/MiniOppgaveOverloads.sln new file mode 100644 index 0000000..1a471c5 --- /dev/null +++ b/Emne 3/MiniOppgaveOverloads/MiniOppgaveOverloads.sln @@ -0,0 +1,10 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + EndGlobalSection +EndGlobal diff --git a/Emne 3/MiniOppgaveOverloads/MiniOppgaveOverloads/MiniOppgaveOverloads.csproj b/Emne 3/MiniOppgaveOverloads/MiniOppgaveOverloads/MiniOppgaveOverloads.csproj new file mode 100644 index 0000000..2f4fc77 --- /dev/null +++ b/Emne 3/MiniOppgaveOverloads/MiniOppgaveOverloads/MiniOppgaveOverloads.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/Emne 3/MiniOppgaveOverloads/MiniOppgaveOverloads/Program.cs b/Emne 3/MiniOppgaveOverloads/MiniOppgaveOverloads/Program.cs new file mode 100644 index 0000000..e2726be --- /dev/null +++ b/Emne 3/MiniOppgaveOverloads/MiniOppgaveOverloads/Program.cs @@ -0,0 +1,10 @@ +namespace MiniOppgaveOverloads +{ + MiniOppgaveOverloads.Run(); + + static void Run() + { + + } + +} diff --git a/Emne 3/MiniOverloads/MiniOverloads.sln b/Emne 3/MiniOverloads/MiniOverloads.sln new file mode 100644 index 0000000..6e14762 --- /dev/null +++ b/Emne 3/MiniOverloads/MiniOverloads.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MiniOverloads", "MiniOverloads\MiniOverloads.csproj", "{6DCE59CD-8964-4AA0-B9DE-BB9B5F4FB9DB}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6DCE59CD-8964-4AA0-B9DE-BB9B5F4FB9DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6DCE59CD-8964-4AA0-B9DE-BB9B5F4FB9DB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6DCE59CD-8964-4AA0-B9DE-BB9B5F4FB9DB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6DCE59CD-8964-4AA0-B9DE-BB9B5F4FB9DB}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/Emne 3/MiniOverloads/MiniOverloads/MiniOverloads.csproj b/Emne 3/MiniOverloads/MiniOverloads/MiniOverloads.csproj new file mode 100644 index 0000000..2f4fc77 --- /dev/null +++ b/Emne 3/MiniOverloads/MiniOverloads/MiniOverloads.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/Emne 3/MiniOverloads/MiniOverloads/Program.cs b/Emne 3/MiniOverloads/MiniOverloads/Program.cs new file mode 100644 index 0000000..c8c7004 --- /dev/null +++ b/Emne 3/MiniOverloads/MiniOverloads/Program.cs @@ -0,0 +1,8 @@ +using MiniOverloads; + +Console.Clear(); + +Message writeMessage = new Message("Hei og velkommen", ", du er grei"); + +writeMessage.PrintWelcomeMessage(); + diff --git a/Emne 3/MiniOverloads/MiniOverloads/WelcomeMessage.cs b/Emne 3/MiniOverloads/MiniOverloads/WelcomeMessage.cs new file mode 100644 index 0000000..9c67b2b --- /dev/null +++ b/Emne 3/MiniOverloads/MiniOverloads/WelcomeMessage.cs @@ -0,0 +1,27 @@ +namespace MiniOverloads +{ + + public class Message + { + string MessageText { get; set; } + string Kompliment { get; set; } + + public Message(string messageText) + { + MessageText = messageText; + } + + public Message(string messageText, string kompliment) + { + MessageText = messageText; + Kompliment = kompliment; + + } + + public void PrintWelcomeMessage() + { + Console.WriteLine($"{MessageText} {Kompliment}"); + } + + } +} \ No newline at end of file diff --git a/Emne 3/MiniOverloadsOppgave/MiniOverloadsOppgave.sln b/Emne 3/MiniOverloadsOppgave/MiniOverloadsOppgave.sln new file mode 100644 index 0000000..1a471c5 --- /dev/null +++ b/Emne 3/MiniOverloadsOppgave/MiniOverloadsOppgave.sln @@ -0,0 +1,10 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + EndGlobalSection +EndGlobal diff --git a/Emne 3/MiniOverloadsOppgave/MiniOverloadsOppgave/MiniOverloadsOppgave.csproj b/Emne 3/MiniOverloadsOppgave/MiniOverloadsOppgave/MiniOverloadsOppgave.csproj new file mode 100644 index 0000000..2f4fc77 --- /dev/null +++ b/Emne 3/MiniOverloadsOppgave/MiniOverloadsOppgave/MiniOverloadsOppgave.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/Emne 3/MiniOverloadsOppgave/MiniOverloadsOppgave/Program.cs b/Emne 3/MiniOverloadsOppgave/MiniOverloadsOppgave/Program.cs new file mode 100644 index 0000000..72df535 --- /dev/null +++ b/Emne 3/MiniOverloadsOppgave/MiniOverloadsOppgave/Program.cs @@ -0,0 +1,23 @@ +namespace MiniOverloadsOppgave +{ + class Welcome + { + void PrintWelcomeMessage() + { + Console.WriteLine("Hei og velkommen!"); + } + + void PrintWelcomeMessage(string kompliment = "Du er Snill") + { + Console.WriteLine($"Hei og velkommen! {kompliment}"); + } + + static void Main(string[] args) + { + Console.WriteLine("Hello World!"); + = PrintWelcomeMessage(); + PrintWelcomeMessage("Du er nokså snill"); + } + + } +} diff --git a/Emne 3/OverloadOgDefault/OverloadOgDefault/Program.cs b/Emne 3/OverloadOgDefault/OverloadOgDefault/Program.cs index 3290ba9..27a0db8 100644 --- a/Emne 3/OverloadOgDefault/OverloadOgDefault/Program.cs +++ b/Emne 3/OverloadOgDefault/OverloadOgDefault/Program.cs @@ -1,5 +1,4 @@ -using System.Formats.Asn1; - + namespace OverloadOgDefault { class Program @@ -21,6 +20,8 @@ namespace OverloadOgDefault return a + b; } } + + static void Main(string[] args) { OverloadExample calculator = new OverloadExample(); @@ -28,6 +29,19 @@ namespace OverloadOgDefault 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)); + int LeggSammen(int tall1 = 2, int tall2 = 3) + { + return tall1 + tall2; + } + void VisSum() + { + int sum = LeggSammen(); + Console.WriteLine("Summen er: " + sum); + int sum2 = LeggSammen(2,2); + Console.WriteLine("Den andre summen er: " + sum2); + } + VisSum(); + } } } \ No newline at end of file