Public string brand = "Ford"; public void honk



Yüklə 0,6 Mb.
səhifə1/3
tarix23.06.2023
ölçüsü0,6 Mb.
#134603
  1   2   3



class Vehicle
{
public string brand = "Ford";
public void honk()
{
Console.WriteLine("Tuut, tuut!");
}
}

class Car : Vehicle


{
public string modelName = "Mustang";
}

class Program


{
static void Main(string[] args)
{
Car myCar = new Car();

myCar.honk();

Console.WriteLine(myCar.brand + " " + myCar.modelName);
}
}
Output:
Tuut, tuut!
Ford Mustang

public delegate void MyDelegate(string msg);


class Program


{
static void Main(string[] args)
{
MyDelegate del = ClassA.MethodA;
InvokeDelegate(del);

del = ClassB.MethodB;


InvokeDelegate(del);

del = (string msg) => Console.WriteLine("Called lambda expression: " + msg);


InvokeDelegate(del);
}

static void InvokeDelegate(MyDelegate del)


{
del("Hello World");
}
}

class ClassA


{
static void MethodA(string message)
{
Console.WriteLine("Called ClassA.MethodA() with parameter: " + message);
}
}

class ClassB


{
static void MethodB(string message)
{
Console.WriteLine("Called ClassB.MethodB() with parameter: " + message);
}
}

Output:


Called ClassA.MethodA() with parameter: Hello World
Called ClassB.MethodB() with parameter: Hello World
Called lambda expression: Hello World
public delegate void MyDelegate(string msg);

class Program


{
static void Main(string[] args)
{
MyDelegate del1 = ClassA.MethodA;
MyDelegate del2 = ClassB.MethodB;

MyDelegate del = del1 + del2;


del("Hello World");

MyDelegate del3 = (string msg) => Console.WriteLine("Called lambda expression: " + msg);


del += del3;
del("Hello World");

del = del - del2;


del("Hello World");

del -= del1


del("Hello World");
}
}

class ClassA


{
static void MethodA(string message)
{
Console.WriteLine("Called ClassA.MethodA() with parameter: " + message);
}
}

class ClassB


{
static void MethodB(string message)
{
Console.WriteLine("Called ClassB.MethodB() with parameter: " + message);
}
}

Output:



After del1 + del2
Called ClassA.MethodA() with parameter: Hello World
Called ClassB.MethodB() with parameter: Hello World
After del1 + del2 + del3
Called ClassA.MethodA() with parameter: Hello World
Called ClassB.MethodB() with parameter: Hello World
Called lambda expression: Hello World
After del - del2
Called ClassA.MethodA() with parameter: Hello World
Called lambda expression: Hello World
After del1 - del1
Called lambda expression: Hello World

public delegate int MyDelegate();


class Program


{
static void Main(string[] args)
{
MyDelegate del1 = ClassA.MethodA;
MyDelegate del2 = ClassB.MethodB;

MyDelegate del = del1 + del2;


Console.WriteLine(del());
}
}

class ClassA


{
static int MethodA()
{
return 100;
}
}

class ClassB


{
static int MethodB()
{
return 200;
}
}

Output:
200

public delegate T add(T param1, T param2);

class Program


{
static void Main(string[] args)
{
add sum = Sum;
Console.WriteLine(sum(10, 20));

add con = Concat;


Console.WriteLine(conct("Salem ","Dunya!!"));
}

public static int Sum(int val1, int val2)


{
return val1 + val2;
}

public static string Concat(string str1, string str2)


{
return str1 + str2;
}
}

Output:
30


Salem Dunya!!

using System;

public class GFG {

public static void addstr(string s1, string s2, string s3)


{
string result = s1 + s2 + s3;
Console.WriteLine("Final string is: " + result);
}

static public void Main()


{
addstr(s1: "Geeks", s2: "for", s3: "Geeks");
}
}
Output:
Final string is: GeeksforGeeks

using System;

class GFG {

public static void Main()


{

string val = "Dog";

CompareValue(ref val);

Console.WriteLine(val);


}

static void CompareValue(ref string val1)


{
if (val1 == "Dog")
{
Console.WriteLine("Matched!");
}

val1 = "Cat";


}
}
Output:
Matched!
Cat

using System;

class GFG {

static public void Main()


{

int num;


AddNum(out num);

Console.WriteLine("The sum of" + " the value is: {0}",num);


}

public static void AddNum(out int num)


{
num = 40;
num += num;
}
}

Output:
The sum of the value is: 80


using System;


class GFG {
static public void detail(string ename, int eid, string bgrp = "A+", string dept = "Review-Team")
{
Console.WriteLine("Employee name: {0}", ename);
Console.WriteLine("Employee ID: {0}", eid);
Console.WriteLine("Blood Group: {0}", bgrp);
Console.WriteLine("Department: {0}", dept);
}
static public void Main()
{
detail("XYZ", 123);
detail("ABC", 456, "B-");
detail("DEF", 789, "B+",
"Software Developer");
}
}

Output:
Employee name: XYZ


Employee ID: 123
Blood Group: A+
Department: Review-Team
Employee name: ABC
Employee ID: 456
Blood Group: B-
Department: Review-Team
Employee name: DEF
Employee ID: 789
Blood Group: B+
Department: Software Developer

using System;

class GFG {

public static void mulval(dynamic val)


{
val *= val;
Console.WriteLine(val);
}

static public void Main()


{
mulval(30);
}
}

Output:
900

using System;

public class GFG {

static public void Main()
{

string str1 = "Geeks";


string str2 = "geeks";
string res = addstr(str1, str2);
Console.WriteLine(res);
}

public static string addstr(string s1, string s2)


{
return s1 + s2;
}
}

Output:
Geeksgeeks


using System;


namespace Examples {

class Geeks {

public static int mulval(params int[] num)
{
int res = 1;

foreach(int j in num)


{
res *= j;
}
return res;
}

static void Main(string[] args)


{

int x = mulval(20, 49, 56, 69, 78);

Console.WriteLine(x);
}
}
}

Output:
295364160




Yüklə 0,6 Mb.

Dostları ilə paylaş:
  1   2   3




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin