Rahul Rajput
Rahul Rajput

Reputation: 1437

Class Declaration in C#

I was searching for reusable Grid for MVC .Net. I found one open source Grid.

In the code I found a pretty interesting class declaration which I didn't understand . Can anybody tell me a detailed description of class declaration below:

public class Grid<TEntity, TSearchForm> : IGrid where  TSearchForm : SearchForm, new()
{
}

Also how do I create an instance of this class?

Upvotes: 3

Views: 1348

Answers (3)

SergeyS
SergeyS

Reputation: 3553

This is generic class inherited from IGrid with two parameters: TEntity, TSearchForm.

Also there is a constraint on type of TSearchForm:

  1. it must be of type SearchForm or below it in hierarchy (able to cast to SearchForm implicitly)

  2. TSearchForm must have public parameterless constructor.

More info:

where (generic type constraint new Constraint

Upvotes: 6

Oded
Oded

Reputation: 499362

The class is a generic class, it implements IGrid.

The two generic type parameters are TEntity and TSearchForm.

TSearchForm is constrained to be SearchForm or a type that inherits from SearchForm and that it has a default constructor.

Suggested reading:

Upvotes: 5

AlexH
AlexH

Reputation: 2700

  • Grid class implements IGrids interface.
  • TSearchFormType must be of type SearchForm (by derivation)
  • TSeachForm must have a constructor without parameters

Upvotes: 6

Related Questions