Understanding Some C # Codes

I read one of the streams only on this site, and I saw some unusual class definition that I could not understand well. Can someone please explain to me what this definition means?

public class Node<T> where T : class
{     
  public Node<T> Next { get; set; }    
  public T Value { get; set; }     
  public Node(T value)     
  { 
    Next = null;
    Value = value;    
  } 
} 

especially where it says

public class Node<T> where T : class
+3
source share
7 answers

This is a definition of a generic class with a generic parameter T with the restriction that T must be a class (reference type).

This essentially means that when creating an instance of Node, you can do

new Node<String>(someStringVar)

but you cannot do

new Node<int>(someIntVar)
+6
source

It is defined Nodeas a generic class , where the generic type is T restricted to reference types only.

+3
source

where T : class , T struct ( , int).

+3

, node, node . T T: . T .

+1

generics

where T : class

, , , , . (, <int> )

Next Node<T>. Size , , Node<Size>.

public Node<T> Next { get; set; }

:

public T Value { get; set; }

,

public Size Value { get; set; }

. generics MSDN

+1

T - . .

+1

T . , T class, struct.

0

All Articles