static void Main(string[] args) { HelloDelegate hd = delegate(string greet) { Console.WriteLine(greet); }; hd.Invoke("Good Morning!!"); AddDelegate ad = delegate(double val1, double val2) { Console.WriteLine(val1 + val2); }; ad.Invoke(123.3446, 2343.44466); subDelegate sd = delegate(double val1, double val2) { Console.WriteLine(val1 - val2); }; sd.Invoke(365.35356, 123.43454); MultiplyDelegate md = delegate(int val1, int val2) { Console.WriteLine(val1 * val2); }; sd.Invoke(125, 132); Console.ReadKey(); }
static void Main(string[] args) { AddnumsDelegate obj1 = delegate(int x, float y) //object creation { return(x + y); }; double result = obj1.Invoke(5, 5.5f); //Invoke Method Console.WriteLine(result); MultiplyDelegate obj2 = delegate(int x, int y) //object creation { return(x + y); }; int result1 = obj2.Invoke(50, 50); //Invoke Method Console.WriteLine(result1); NamesDelegate obj3 = delegate(string Abhigna) //object creation { return(" This " + Abhigna + " my "); }; string result2 = obj3.Invoke("is"); //Invoke Method Console.WriteLine(result2); WishDelegate obj4 = delegate(String sir) //object creation { return(" practise " + sir + " yes "); }; string result3 = obj4.Invoke("file "); //Invoke Method Console.WriteLine(result3); CheckLengthDelegate obj5 = delegate(string name) //object creation { if (name.Length > 5) { return(true); } return(false); }; bool check = obj5.Invoke(" sir "); //Invoke Method Console.WriteLine(check); CheckLength1Delegate obj6 = delegate(string namee) //object creation { if (namee.Length < 3) { return(true); } return(false); }; bool check1 = obj6.Invoke(" AbhignaThammana ");//Invoke Method Console.WriteLine(check1); Console.ReadLine(); }
public static void ShowLambdaExpression() { //Используем лямбда выражение MultiplyDelegate multiplyDelegate = t => t * 2; Console.WriteLine(multiplyDelegate(4)); }
static void Main(string[] args) { AddnumsDelegate obj1 = (int x, float y) => //Lambda expression { return(x + y); //return operation }; double result = obj1.Invoke(5, 5.5f); //Invoking values Console.WriteLine(result); MultiplyDelegate obj2 = (int x, int y) => { return(x + y); }; int result1 = obj2.Invoke(50, 50); Console.WriteLine(result1); NamesDelegate obj3 = Ramya => { Console.WriteLine(" Hai " + Ramya + " welcome "); }; obj3.Invoke("Ramya"); Console.ReadLine(); }
static void Main(string[] args) { AddnumsDelegate obj1 = delegate(int x, int y) //object creation { return(x + y); }; int result = obj1.Invoke(5, 5); Console.WriteLine(result); MultiplyDelegate obj2 = delegate(int x, float y) //object creation { return(x * y); }; double result1 = obj2.Invoke(3, 3.4f); Console.WriteLine(result1); CheckLengthDelegate obj3 = delegate(string name) { if (name.Length > 3) { return(true); } return(false); }; bool check = obj3.Invoke("CSHARP"); Console.WriteLine(check); Console.ReadLine(); }
static void Main(string[] args) { AddnumsDelegate obj1 = (int x, float y) => { return(x + y); }; double result = obj1.Invoke(5, 5.5f); Console.WriteLine(result); MultiplyDelegate obj2 = (int x, int y) => { return(x + y); }; int result1 = obj2.Invoke(50, 50); Console.WriteLine(result1); NamesDelegate obj3 = was => { Console.WriteLine(" This " + was + " my "); }; obj3.Invoke("was"); WishDelegate obj4 = sir => { Console.WriteLine(" my " + sir + "file "); }; obj4.Invoke("practice "); CheckLengthDelegate obj5 = name => { if (name.Length > 5) { return(true); } return(false); }; bool check = obj5.Invoke(" Sowmya "); Console.WriteLine(check); CheckLength1Delegate obj6 = namee => { if (namee.Length < 3) { return(true); } return(false); }; bool check1 = obj6.Invoke(" Ramyasree "); Console.WriteLine(check1); Console.ReadLine(); }
static NativeLibMethods() { LibHandle = NativeMethods.LoadLibrary(LibraryName); MultiplyPtr = NativeMethods.GetProcAddress(LibHandle, "Multiply"); Multiply = Marshal.GetDelegateForFunctionPointer <MultiplyDelegate>(MultiplyPtr); GetFirstCharPtr = NativeMethods.GetProcAddress(LibHandle, "GetFirstChar"); GetFirstChar = Marshal.GetDelegateForFunctionPointer <GetFirstCharDelegate>(GetFirstCharPtr); }
//Type[] definedTypes = { // typeof(Vector2), // typeof(Vector3), // typeof(Vector4) ... //}; /// <summary> /// Construct Weighted Mean class. /// </summary> /// <param name="valueCount">Max number of values to find the average of. Oldest added values are automatically removed.</param> /// <param name="md">Delegate which multiplies value type T by a float and returns the result as type T</param> /// <param name="ad">Delegate which adds two values of type T and returns the result as type T</param> public WeightedMean(int valueCount, MultiplyDelegate md, AddDelegate ad) { // We could instead check if typeof(T) is in list of definedTypes. Which is faster? //if(T is Vector2 || T is Vector3 || T is Vector4 || T is int || T is float || T is double || T is long) { //} multiplyFn = md; addFn = ad; m_values = new FixedStack <T>(valueCount); }
public static void ShowLambdaExpression() { //Используем лямбда выражение //MultiplyDelegate multiplyDelegate = delegate (int t) //{ // return t * 2; //}; MultiplyDelegate multiplyDelegate = t => t * 2; Console.WriteLine(multiplyDelegate(4)); }
static void Main(string[] args) { //- Lav en Lambda Expression der tager imod en int og returnerer tallet fordoblet. Gem i en passende delegate, og kør. MultiplyDelegate del1 = x => x * 2; Console.WriteLine(del1(50)); // - Lav en Lambda Expression der tager imod 3 floats og returnerer summen. Gem i en passende delegate, og kør. SumOfFloatsDelegate del2 = (x1, x2, x3) => x1 + x2 + x3; Console.WriteLine(del2(12.1F, 1.5F, 2.7F)); //- Lav en Lambda Expression der ikke tager imod noget og returnerer "Hello World". Gem i en passende delegate og kør. TextMakerDelegate del3 = () => "Hello World"; Console.WriteLine(del3()); //Udfordring //addition MyFloatDelegate floatDelAddition = (num1, num2) => num1 + num2; Console.WriteLine(floatDelAddition(2.2f, 40f)); //substraction MyFloatDelegate floatDelSubstration = (num1, num2) => num1 - num2; Console.WriteLine(floatDelSubstration(99.1f, 30.3f)); //division MyIntDelegate intDelDivision = (num1, num2) => num1 / num2; Console.WriteLine(intDelDivision(10, 5)); //Multiply MyStringDelegate stringDelMultiply = (text1, text2) => { if (!int.TryParse(text1, out int int1)) { throw new ArgumentException("Argument must be number.", "text1"); } if (!int.TryParse(text2, out int int2)) { throw new ArgumentException("Arguement must be a number.", "text2"); } return((int1 * int2).ToString()); }; Console.WriteLine(stringDelMultiply("10", "20")); }
//} static void Main(string[] args) { staticpara d = new staticpara(); MyDelegate del = Multiplication.Multiply; InvokeDelegate(del); MultiplyDelegate del1 = new MultiplyDelegate(d.Multiplynums); del1(100, 50); d.Multiplynums(100, 50); del = (string msg) => Console.WriteLine("Called lambda expression: " + msg); InvokeDelegate(del); }
static void Main(string[] args) { AddnumsDelegate obj1 = new AddnumsDelegate(Addnums); int result = obj1.Invoke(5, 5); Console.WriteLine(result); MultiplyDelegate obj2 = new MultiplyDelegate(Multiply); double result2 = obj2.Invoke(4, 5); Console.WriteLine(result2); MethodDelegate obj3 = new MethodDelegate(Method); obj3.Invoke("RAMYA"); Console.ReadLine(); }