Skip to main content
added 222 characters in body
Source Link
Patko
  • 4.4k
  • 1
  • 34
  • 27

According to the docs you can constrain TT to be a value type using the where keyword

where T: struct 

Class declaration would then look like sothis:

class Something<T> where T: struct { ... }  

Though stringstring is not a value type and you won't be able to use it with such a constraint. Maybe IComparable would be better in case you want to also use the string type. 

As for specifying the default type, I don't believe it is possible.

According to the docs you can constrain T to be a value type like so

where T: struct 

Though string is not a value type and you won't be able to use it with such a constraint. As for specifying the default type, I don't believe it is possible.

According to the docs you can constrain T to be a value type using the where keyword

where T: struct 

Class declaration would then look like this:

class Something<T> where T: struct { ... }  

Though string is not a value type and you won't be able to use it with such a constraint. Maybe IComparable would be better in case you want to also use the string type. 

As for specifying the default type, I don't believe it is possible.

Source Link
Patko
  • 4.4k
  • 1
  • 34
  • 27

According to the docs you can constrain T to be a value type like so

where T: struct 

Though string is not a value type and you won't be able to use it with such a constraint. As for specifying the default type, I don't believe it is possible.