KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Sometimes it's useful to have something like: class X { ... } class Y { X X { get { ... } set { ... } } } because X describes both what the type is (as a class name), and the value being accessed/mutated (as the property name). So far so good. Suppose you wanted to do the same thing, but in a generic way: class Z<T> { T T { get { ... } set { ... } } } For this example, the compiler complains that: The type 'Z<T>' already contains a definition for 'T' . This happens for properties, variables and methods, and I don't quite understand why - surely the compiler knows that T is a type and can therefore figure it out the same way as in the first example? Short version: Why does the first example work, but not the second? EDIT: I've just discovered that if I "Refactor > Rename" the type parameter, say from T to U, the IDE changes it to: class Z<U> { U T { get { ... } set { ... } } } so something in there knows what's a type and what's a member name
Tags (comma-separated)
Save Edits
Cancel