Overload finally
This commit is contained in:
parent
8a1b696755
commit
0aa442271f
10
Emne 3/MiniOppgaveOverloads/MiniOppgaveOverloads.sln
Normal file
10
Emne 3/MiniOppgaveOverloads/MiniOppgaveOverloads.sln
Normal 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
|
|
@ -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>
|
10
Emne 3/MiniOppgaveOverloads/MiniOppgaveOverloads/Program.cs
Normal file
10
Emne 3/MiniOppgaveOverloads/MiniOppgaveOverloads/Program.cs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
namespace MiniOppgaveOverloads
|
||||||
|
{
|
||||||
|
MiniOppgaveOverloads.Run();
|
||||||
|
|
||||||
|
static void Run()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
16
Emne 3/MiniOverloads/MiniOverloads.sln
Normal file
16
Emne 3/MiniOverloads/MiniOverloads.sln
Normal 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
|
10
Emne 3/MiniOverloads/MiniOverloads/MiniOverloads.csproj
Normal file
10
Emne 3/MiniOverloads/MiniOverloads/MiniOverloads.csproj
Normal 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>
|
8
Emne 3/MiniOverloads/MiniOverloads/Program.cs
Normal file
8
Emne 3/MiniOverloads/MiniOverloads/Program.cs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
using MiniOverloads;
|
||||||
|
|
||||||
|
Console.Clear();
|
||||||
|
|
||||||
|
Message writeMessage = new Message("Hei og velkommen", ", du er grei");
|
||||||
|
|
||||||
|
writeMessage.PrintWelcomeMessage();
|
||||||
|
|
27
Emne 3/MiniOverloads/MiniOverloads/WelcomeMessage.cs
Normal file
27
Emne 3/MiniOverloads/MiniOverloads/WelcomeMessage.cs
Normal 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}");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
10
Emne 3/MiniOverloadsOppgave/MiniOverloadsOppgave.sln
Normal file
10
Emne 3/MiniOverloadsOppgave/MiniOverloadsOppgave.sln
Normal 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
|
|
@ -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>
|
23
Emne 3/MiniOverloadsOppgave/MiniOverloadsOppgave/Program.cs
Normal file
23
Emne 3/MiniOverloadsOppgave/MiniOverloadsOppgave/Program.cs
Normal 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");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,4 @@
|
||||||
using System.Formats.Asn1;
|
|
||||||
|
|
||||||
namespace OverloadOgDefault
|
namespace OverloadOgDefault
|
||||||
{
|
{
|
||||||
class Program
|
class Program
|
||||||
|
@ -21,6 +20,8 @@ namespace OverloadOgDefault
|
||||||
return a + b;
|
return a + b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
OverloadExample calculator = new OverloadExample();
|
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 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 tre int-parametre: " + calculator.Add(2, 3, 9));
|
||||||
Console.WriteLine("Sum med to double-parametere: {0}", calculator.Add(2.3, 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();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue