Delegates, Anonymous Delegates, Lambdas,
This article (part1) forms part of a mini series which willand Generics
What is a Delegate?
Can i ask again, What is a Delegate?
My first answer would be "You can think of a delegate as an object that holds one or more methods".Normally we don't just go ahead and execute an object, but rather we do the following:
- Declare the type
- Declare a variable of the type
- Instantiate the variable and set properties
- Use the variable
public class Car
{
private int speed = 0;
public string Make{get;set;}
public string Model{get;set;}
public void Accelerate()
{
speed = 210
}
}
//Declare a variable of the type
Car fastCar;
//Instantiate the variable and set properties
fastCar = new Car(){ Make = "Porshe", Model = "950" };
//Use the variable
fastCar.Accelerate();
A delegate is a type that has already been created by the .Net team.
For a delegate we do something similar:
- Declare the delegate type
- Declare a variable of the delegate type
- Create an instance of the delegate and set it's reference
A delegate is already a type that is part of the .Net framework class library
Multicast
At Assemblysoft we specialise in Custom Software Development tailored to your requirements. We have experience creating Booking solutions, as we did for HappyCamperVan Hire. You can read more here.
We can onboard and add value to your business rapidly. We are an experienced Full-stack development team able to provide specific technical expertise or manage your project requirements end to end. We specialise in the Microsoft cloud and .NET Solutions and Services. Our developers are Microsoft Certified. We have real-world experience developing .NET applications and Azure Services for a large array of business domains. If you would like some assistance with Azure | Azure DevOps Services | Blazor Development or in need of custom software development, from an experienced development team in the United Kingdom, then please get in touch, we would love to add immediate value to your business.
Assemblysoft - Your Safe Pair of Hands
Comments
Post a Comment