Jump to content

Recommended Posts

Posted

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

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Popular Days

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...