- Foo<string>("abc");
- private void Foo
(T value) where T : struct - {
- //...
- }
The simple solution is creating overwrite method:
- private void Foo
(T value) where T : string - {
- //...
- }
Nice, but not perfect. The beautiful idea was offered by KeithS instead to restrict a value to struct change it to IConvertible. Next types implemented an interface IConvertible but now String can be included in the constraint:
Boolean
Byte
Char
DateTime
Decimal
Double
Int16
Int32
Int64
SByte
Single
String
Type
UInt16
UInt32
UInt64
Final:
- private void Foo
(T value) where T : IConvertible - {
- //...
- }