Generics
Generics are powerful – they allow you to develop the same method (or class) for different types of variables.
1 | Public class adding <T> |
In this case we added a class named adding, which takes a variable type
This is good, because since C# is hard typed, if you wanted to create an Add function, you might need to create one to add integers, another for floats, and another for long numbers. Instead you can use this one class.
Here is an example from class.
1 | namespace EmployeeDirectory.Shared.Interfaces |
In this example we have created a Result object. It will be used to return result objects back from functions. The idea is rather than returning a ‘employee’ object. You’ll return a result object, which has an ‘employee’ object in its Model method.
A function using this interface would look like this
1 | public IResult<List<EmployeeViewModel>> GetAllEmployess() |
The program calling the function will look like this
1 | [HttpGet] |