NewsBot
1
I seem to be making every mistake it's possible to make as I work my way using Generics seriously for the first time.
This time I want to know why I can't call a static method on a generic type, even though a static method is defined on the interface that the generic type must conform to.
thus:
interface ISomething
{
***static void Bob()
}
class theClass
{
***public void T TheMethod() where T : ISomething
***{
******T.Bob(); //Compiler throws a fit*
***}
}
The fit the compiler throws is complaining that*"T is a 'type parameter'*which is not valid in the given context.
[edit: alright, more digging turfs up that it's apparantly because inheritance doesn't apply to static methods. (my actual code uses an abstract class, so perhaps the interface code above couldn't have compiled anyway.)
Hmmmm...
So how to get at something type-specific... I think i'll have to use those things that I've just forgotten the name of that go above your declaration in square brackets...Attributes! that's the cookie!]
More...
View All Our Microsft Related Feeds
This time I want to know why I can't call a static method on a generic type, even though a static method is defined on the interface that the generic type must conform to.
thus:
interface ISomething
{
***static void Bob()
}
class theClass
{
***public void T TheMethod() where T : ISomething
***{
******T.Bob(); //Compiler throws a fit*
***}
}
The fit the compiler throws is complaining that*"T is a 'type parameter'*which is not valid in the given context.
[edit: alright, more digging turfs up that it's apparantly because inheritance doesn't apply to static methods. (my actual code uses an abstract class, so perhaps the interface code above couldn't have compiled anyway.)
Hmmmm...
So how to get at something type-specific... I think i'll have to use those things that I've just forgotten the name of that go above your declaration in square brackets...Attributes! that's the cookie!]
More...
View All Our Microsft Related Feeds