Questions tagged [generic-constraints]

A generic constraint will restrict the types that can be used for a specific generic. Use this tag for questions regarding generic constraints.

allow a programmer to restrict the types, which can be used for specific . This will also allow the compiler to ensure that specific object members exist. Therefore programmers can write more flexible code.

This feature is implemented in a range of languages including , , , , and .

136 questions
-3
votes
2 answers

Generic method add new T to list of T

I am trying to pass a generic list to a function which will add a new item to the list. I have the following stripped down example: private void SetBayNumb(ObservedList bayList) where T : IBaySpec, new() { var bay = new T(); …
DBHC
  • 95
  • 12
1 2 3
9
10