Skip to content

Commit

Permalink
#26 메서드 오버로딩 예제
Browse files Browse the repository at this point in the history
  • Loading branch information
guddus326 committed Jul 1, 2021
1 parent 1d96f88 commit 1ce7d02
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions CSBasic5/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,26 @@ public static int Abs(int input)
return input;
}*/
}

public static double Abs(double input)
{
return (input < 0) ? -input : input;
}

// Abs( long )
public static long Abs(long input)
{
return (input < 0) ? -input : input;
}

// Abs( long )
/* Method Signature가 같은 경우 오버로딩 불가!
public static int Abs(long a2)
{
return 0;
}
*/

}

class Test
Expand Down Expand Up @@ -79,6 +99,11 @@ static void Main(string[] args)
Program p = new Program();
Console.WriteLine(p.instanceVariable);
p.instanceMethod();

Console.WriteLine(MyMath.Abs(52));
Console.WriteLine(MyMath.Abs(-273));
Console.WriteLine(MyMath.Abs(52.273));
Console.WriteLine(MyMath.Abs(21474812312323));
}
}
}

0 comments on commit 1ce7d02

Please sign in to comment.