Calling an overloaded generic method

P

Peter Morris

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

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



Thanks


Pete
 
N

Nicholas Paldino [.NET/C# MVP]

Pete,

You will have to cast the null, like so:

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

Pavel Minaev

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)".
 
P

Pavel Minaev

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)".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top