Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old August 28th, 2008, 03:55 PM
Peter Morris
Guest
 
Posts: n/a
Default Calling an overloaded generic method

public void DoSomething<T>(object value)
{
<code omitted>
}

public void DoSomething<T>()
{
How do I now call this.DoSomething<T>(null);
}



Thanks


Pete
  #2  
Old August 28th, 2008, 04:15 PM
Nicholas Paldino [.NET/C# MVP]
Guest
 
Posts: n/a
Default Re: Calling an overloaded generic method

Pete,

You will have to cast the null, like so:

this.DoSomething<T>((object) null);


--
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com

"Peter Morris" <mrpmorrisNO@SPAMgmail.comwrote in message
news:eLZx5yRCJHA.4884@TK2MSFTNGP02.phx.gbl...
Quote:
public void DoSomething<T>(object value)
{
<code omitted>
}
>
public void DoSomething<T>()
{
How do I now call this.DoSomething<T>(null);
}
>
>
>
Thanks
>
>
Pete

  #3  
Old August 28th, 2008, 05:25 PM
Peter Morris
Guest
 
Posts: n/a
Default Re: Calling an overloaded generic method

Ahh. I thought it *should* work. Thanks!


Pete
  #4  
Old August 29th, 2008, 08:05 AM
Pavel Minaev
Guest
 
Posts: n/a
Default Re: Calling an overloaded generic method

On Aug 28, 6:45*pm, "Peter Morris" <mrpmorri...@SPAMgmail.comwrote:
Quote:
public void DoSomething<T>(object value)
{
* * <code omitted>
>
}
>
public void DoSomething<T>()
{
* * How do I now call this.DoSomething<T>(null);
>
}
With the code as written, it should be just "DoSomething<T>(null)" -
there are no ambiguities here. Perhaps you've meant the first
signature to be "DoSomething<T>(T)"? Then you could either use the
cast as suggested, or explicitly specify T on call:
"DoSomething<object>(null)".
  #5  
Old August 29th, 2008, 08:05 AM
Pavel Minaev
Guest
 
Posts: n/a
Default Re: Calling an overloaded generic method

On Aug 28, 6:45*pm, "Peter Morris" <mrpmorri...@SPAMgmail.comwrote:
Quote:
public void DoSomething<T>(object value)
{
* * <code omitted>
>
}
>
public void DoSomething<T>()
{
* * How do I now call this.DoSomething<T>(null);
>
}
With the code as written, it should be just "DoSomething<T>(null)" -
there are no ambiguities here. Perhaps you've meant the first
signature to be "DoSomething<T>(T)"? Then you could either use the
cast as suggested, or explicitly specify T on call:
"DoSomething<object>(null)".
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles