Overload finally

This commit is contained in:
Geir Okkenhaug Jerstad 2024-11-27 09:43:48 +01:00
parent 8a1b696755
commit 0aa442271f
11 changed files with 150 additions and 2 deletions

View file

@ -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

View file

@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View file

@ -0,0 +1,10 @@
namespace MiniOppgaveOverloads
{
MiniOppgaveOverloads.Run();
static void Run()
{
}
}

View file

@ -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

View file

@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View file

@ -0,0 +1,8 @@
using MiniOverloads;
Console.Clear();
Message writeMessage = new Message("Hei og velkommen", ", du er grei");
writeMessage.PrintWelcomeMessage();

View file

@ -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}");
}
}
}

View file

@ -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

View file

@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View file

@ -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");
}
}
}

View file

@ -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();
}
}
}