Professional Documents
Culture Documents
Delegates
Delegates
using System;
using System.Collections.Generic;
namespace Delegates
{
public delegate bool IsClearedDelegate(Student stu);
public class Student
{
public int ID { get; set; }
public string Name { get; set; }
public int Marks { get; set; }
Student.ClearedAssessment(students, delObj);
}
The return type and Signature of the delegate must match with the return type and
signature of the function that delegate points to.
Syntax of the delegate looks very similar to a method with a delegate keyword.
Multicast Delegates
A multicast delegate is a delegate that has references to more than one function.
When we invoke a multicast delegate, all the functions that delegate is pointing to are invoked.
A multicast delegate invokes the methods in the same order in which they are referenced.
sing System;
namespace MulticastDelegates
{
public delegate void MySampleDelegate();
internal class Program
{
static void Main(string[] args)
{
MySampleDelegate delObj = new MySampleDelegate(Method1);
delObj += Method3;
delObj += Method2;
delObj();
}
public static void Method1()
{
Console.WriteLine("Method1 invoked..!!");
}
public static void Method2()
{
Console.WriteLine("Method2 invoked..!!");
}
public static void Method3()
{
Console.WriteLine("Method3 invoked..!!");
}
}
}
sing System;
namespace MulticastDelegates
{
public delegate void MySampleDelegate();
internal class Program
{
static void Main(string[] args)
{
MySampleDelegate delObj = new MySampleDelegate(Method1);
delObj += Method3;
delObj += Method2;
delObj();
}
public static void Method1()
{
Console.WriteLine("Method1 invoked..!!");
}
public static void Method2()
{
Console.WriteLine("Method2 invoked..!!");
}
public static void Method3()
{
Console.WriteLine("Method3 invoked..!!");
}
}
}
Reflection is the ability of inspecting an assembly metadata at runtime. It is used to find all types
in an assembly and dynamically invoke methods in the assembly.
using System;
using System.IO;
namespace FileHandling
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("--------------------------------------------------------");
Console.WriteLine("Delete Directory");
DirectoryInfo deleteDirInfo = new DirectoryInfo(@"D:\Demos");
Console.WriteLine("Name : {0}", deleteDirInfo.FullName);
Console.WriteLine("Are you sure to delete..!!");
string str = Console.ReadLine();
if(str == "y" || str=="Y")
{
Directory.Delete(@"D:\Demos", true);
Console.WriteLine("Directory deleted..!!");
}
}
}
}
namespace FileHandling
{
internal class Program
{
static void Main(string[] args)
{
//Reading & Writing to a file using Stream Reader & StreamWriter Class
}
}
}
using System;
using System.IO;
namespace FileHandling
{
internal class Program
{
static void Main(string[] args)
{
//Reading & Writing to a file using Stream Reader & StreamWriter Class
using System;
using System.IO;
namespace FileHandling
{
internal class Program
{
static void Main(string[] args)
{
//Reading & Writing to a file using Stream Reader & StreamWriter Class
using System;
using System.IO;
namespace FileHandling
{
internal class Program
{
static void Main(string[] args)
{
//Reading & Writing to a file using File class
}
}
}
namespace FileHandling
{
internal class Program
{
static void Main(string[] args)
{
//Append data to the existing file using StreamWriter & File classes
}
}
}
using System;
using System.IO;
namespace FileHandling
{
internal class Program
{
static void Main(string[] args)
{
//StringWriter and StringReader -> these classes are used for reading form and writing to
strings
//as if they were streams. these classes are used to perform In-memory text manipulation
}
}
}
has context menu