overloading

This commit is contained in:
Geir Okkenhaug Jerstad 2024-11-25 15:00:30 +01:00
parent f186fcf653
commit 558073a24d
3 changed files with 59 additions and 0 deletions

View file

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

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,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));
}
}
}