Reviewer
| Navigation: Index | Azure | .NET | SQL | React | General |
Extension methods allow you to add methods to existing types without modifying them. To create an extension method:
public static class StringExtensions
{
public static bool IsNullOrEmpty(this string str)
{
return string.IsNullOrEmpty(str);
}
}
Dependency Injection (DI) is a design pattern used to implement IoC (Inversion of Control), allowing the creation of dependent objects outside of a class and providing those objects to a class in various ways. Example:
public interface IService { }
public class Service : IService { }
public class Client
{
private readonly IService _service;
public Client(IService service)
{
_service = service;
}
}
Generics allow you to define a class or method with a placeholder for the type of data it stores or uses. Example:
public class GenericClass<T>
{
public T Data { get; set; }
}
A derived class is a class that inherits from another class. You can identify it by the : symbol. Example:
public class BaseClass { }
public class DerivedClass : BaseClass { }
Async and await are used for asynchronous programming. Example:
public async Task<int> GetDataAsync()
{
await Task.Delay(1000);
return 42;
}
The virtual keyword is used to modify a method, property, indexer, or event declaration and allow it to be overridden in a derived class. Example:
public class BaseClass
{
public virtual void Display() { }
}
public class DerivedClass : BaseClass
{
public override void Display() { }
}
Abstraction involves hiding the complex implementation details and showing only the necessary features of an object.
A sealed class cannot be inherited. Example:
public sealed class SealedClass { }
Access modifiers define the visibility of a class and its members. Examples include public, private, protected, and internal.
The yield keyword is used to return each element one at a time in an iterator method. Example:
public IEnumerable<int> GetNumbers()
{
yield return 1;
yield return 2;
yield return 3;
}
A constructor is a special method that initializes an object. Types include default, parameterized, and static constructors.
A destructor is a method that is called when an object is destroyed. It is used to release unmanaged resources.
The garbage collector automatically manages memory by reclaiming memory occupied by objects that are no longer in use.
A delegate is a type that represents references to methods with a specific parameter list and return type. Example:
public delegate void MyDelegate(string message);
Unit tests are automated tests that verify the correctness of a small piece of code. Frameworks include MSTest, NUnit, and xUnit.
Middleware are components that are used to handle requests and responses in an ASP.NET Core application pipeline.