شرح ال overloading في لغة سي شارب عن طريق مثالين

برمجة سي شارب | c# programming 

  • 2024-03-09

شرح ال overloading في لغة سي شارب عن طريق مثالين

-----------------

Write a C# program using the concept of overloading and write the output of the following: -Addition(int a, int b) where parameters are (2,3) - Addition(double a, double b) where parameters are (3.5,4.9)

public static void Main()

{

int add1 = Addition(2,3); //function call

double add2 = Addition(3.5,4.9); //function call

Console.WriteLine("The addition of integers is:"+

add1); // Print add1

Console.WriteLine("The addition of double is:"+ add2); //Print add2

}

public static int Addition(int a,int b) {

return a+b;

}

public static double Addition(double a,double b )

{

return a+b;

}

 

============================================

Read the following C# code and answer the questions.

using System;

public class Program {

public static void Main() {

int res1;

double res2;

res1=.................; //calling function (mul)

res2=.................; //calling function(sqr)

Console.WriteLine("The multiplication of two numbers is:"+ res1);

Console.WriteLine("The square of 2 is:"+ res2);

}

public static int mul(int a,int b) {

.........................

..........................

..........................

}

public static double sqr(int n) {

..............................

..............................

...............................

}

}

Function Building:

a.mul(int a,int b) return the total of two numbers.

b.sqr(int n)function to print the square of n.

Function call

a.Call function sum(int a, int b)where parameters are 2 and 3.

b.Call function sqr(int n) where parameter is 2 Sol)

using System;

public class Program {

public static void Main() {

int res1;

double res2;

res1=mul(2,3); //calling function (mul)

res2=sqr(2); //calling function(sqr)

Console.WriteLine("The multiplication of two numbers is:"+ res1);

Console.WriteLine("The square of 2 is:"+ res2);

}

public static int mul(int a,int b) {

int multiply;

multiply=a*b;

return multiply;

}

public static double sqr(int n) {

int square;

square=n*n;

return square;

}

}

هل كان الشرح مفيد؟

avatar
mr.geek

  • عن بعد/اونلاين
  • شروحات مشابهة

    • برمجة سي شارب | c# programming
    • برمجة | Programming
    • برمجة جافا | Java programming
    • برمجة بي اتش بي | Php programming
    • برمجة html | Html programming
    • برمجة سي اس اس | Css programming
    • برمجة روبي | Ruby programming
    محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
    ماهو التخصص الذي تبحث عنه؟
    اكتب هنا...