redefinition of generic methods
- From: "Wiktor Zychla [C# MVP]" <wzychla@xxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 26 Apr 2006 13:53:27 +0200
it is obvious that you cannot have two [or more] methods that differ only on returning value:
void F() { }
int F() { }
it is however interesting (and to me : surprizing) that this restriction also applies to generic methods that differ on constraints:
T F<T>() where T : class { }
T F<T>() where T : struct { }
note that constraints are strictly exclusive here. it would be deterministic then for the compiler to pick a method to call:
string s = F<string>(); // pick first F
int i = F<int>(); // pick second F
I do not think that this is a compiler-only issue, I belive it is rather caused by IL limitations. However, since .NET constraints are significantly limited, I belive it would be easy to determine if constraints are exclusive or not in general case [Am I wrong?].
Wiktor Zychla
.
- Follow-Ups:
- Re: redefinition of generic methods
- From: Laura T.
- Re: redefinition of generic methods
- Prev by Date: Re: What does this mean [DefaultValue(false)]
- Next by Date: Re: What does this mean [DefaultValue(false)]
- Previous by thread: C# Extended Text Editor
- Next by thread: Re: redefinition of generic methods
- Index(es):
Relevant Pages
|