C # function overloading

Source: Internet
Author: User

Function names must be the same to form function overloads;

function return value type: can be the same or different (note: The return type of the function is not sufficient to distinguish two overloaded functions);

Function parameter type: must be different;

Number of function arguments: can be the same, can be different

function parameter order: can be the same, can be different;

Example: A point on the center of a known circle and a circular edge

public static double area (int x1, int y1, int x2, int y2)

{
int x = x2-x1;int y = y2-y2;double r = (double) math.s QRT (X*x+y*y); Console.WriteLine ("This is a circle in the circle ({0},{1}), around the circle ({2},{3}), the radius of the circle is {4}", x1,y1,x2,y2,r); return area (R);} static void Main (string[] args) {int x1=2,x2=4; x-coordinate int y1=3,y2=5; Y-coordinate double radius=3; Radius double circlearea = 0; Circlearea = Area (); Console.WriteLine ("-->1. Area of {0}", Circlearea); Console.WriteLine (); Circlearea = Area (x1,y1); Console.WriteLine ("-->2. Area of {0}", Circlearea); Console.WriteLine (); Circlearea = Area (RADIUS); Console.WriteLine ("-->3. Area of {0}", Circlearea); Console.WriteLine (); Circlearea = Area (x1, y1, radius); Console.WriteLine ("-->4. Area of {0}", Circlearea); Console.WriteLine (); Circlearea = Area (x1, y1, x2, y2); Console.WriteLine ("-->5. Area of {0}", Circlearea); Console.WriteLine (); Console.ReadLine (); }

C # function overloading

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.