Click here to Skip to main content
15,902,114 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
public delegate void BindGtype<int>(T id);

 var PointGtypeMethod = new BindGtype<int>(BindGasTypes);
 PointGtypeMethod(;   -----------------------------------------------------> how to call here ?

  public void BindGasTypes<int>(T UserID)
    {
        try
        {
            var ds = WeldService.GetUserSelectedGasTypeDetails(UserID);

            gvGas.DataSource = ds;
            gvGas.DataBind();
        }
        catch (Exception ex)
        { }

    }
Posted
Updated 26-Jun-13 23:19pm
v2
Comments
johannesnestler 27-Jun-13 3:46am    
no question, seems to be incomplete
OriginalGriff 27-Jun-13 3:57am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Use the "Improve question" widget to edit your question and provide better information.

1 solution

Hi anbujerimiah,

After reading your - non question ;-) - again. I think I can guess what you want to know.

So your delegate Definition should be generic (it is wrong...)
public delegate void BindGtype<T>(T id);


Let's say you have a generic method matching your delegate type BindGtype
void AMethod<T>(T id) {}


Then you can create a new function pointer to this method like this:
var PointGtypeMethod = new BindGtype<int>(AMethod);


and you can do the same to point to an already "specialized" (non-generic) method
void AnotherMethod(int id) {}
var PointGtypeMethod = new BindGtype<int>(AnotherMethod);


Does this help?

Kind regards

Johannes
 
Share this answer
 
v5
Comments
anbujeremiah 27-Jun-13 5:33am    
Thanks Johannes.

i have another doubt, in your last line ... you mentioned

and you can do the same to point to an already "specialized" (non-generic) method

void AnotherMethod(int id) {}

Do you mean AMethod is AnotherMethod or both different methods

Also PointGtypeMethod(function pointer) will it point to AnotherMethod ?

Many Thanks
johannesnestler 27-Jun-13 5:50am    
AMethod is a generic method (with an type Argument T) while AnotherMehtod is a "normal" (non-generic) method. So, when you create a function pointer, the pointed method must match the signature of your function pointer type (=delegate). What I wanted to show you is just that a generic delegate does not need to point to generic methods, but if you do so, C# deduces the correct type from the delegates type parameter also for the generic method (you dont't have to write: new BindGtype<int>(AMethod+TYPEPARAMETER)). But in normal use cases you will have a generic delegate (EventHandler<t> is a good example)and a lot of different non-generic methods you can point to (again the different event-handler methods in a typical .NET GUI Project are a good example)
johannesnestler 27-Jun-13 5:54am    
(updated solution)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900