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