Skip to main content
added 23 characters in body
Source Link

I'm attempting to write a generic method based on the following myMethod:

void myMethod(myClassA instanceA, myClassB instanceB)
{
    instanceA = new myClassA(instanceB);
}

What I've got so far is something like this (myMethod_new), which has some errors:

void myMethod_new<S, T>(S instanceA, T instanceB) where S : new()
{
    instanceA = new S(instanceB);
}

However, since I've not mastered how generics work in C#, how should this be implemented?

I'm attempting to write a generic method based on the following myMethod:

void myMethod(myClassA instanceA, myClassB instanceB)
{
    instanceA = new myClassA(instanceB);
}

What I've got so far is something like this (myMethod_new):

void myMethod_new<S, T>(S instanceA, T instanceB) where S : new()
{
    instanceA = new S(instanceB);
}

However, since I've not mastered how generics work in C#, how should this be implemented?

I'm attempting to write a generic method based on the following myMethod:

void myMethod(myClassA instanceA, myClassB instanceB)
{
    instanceA = new myClassA(instanceB);
}

What I've got so far is something like this (myMethod_new), which has some errors:

void myMethod_new<S, T>(S instanceA, T instanceB) where S : new()
{
    instanceA = new S(instanceB);
}

However, since I've not mastered how generics work in C#, how should this be implemented?

Source Link

C# generics creating new instances

I'm attempting to write a generic method based on the following myMethod:

void myMethod(myClassA instanceA, myClassB instanceB)
{
    instanceA = new myClassA(instanceB);
}

What I've got so far is something like this (myMethod_new):

void myMethod_new<S, T>(S instanceA, T instanceB) where S : new()
{
    instanceA = new S(instanceB);
}

However, since I've not mastered how generics work in C#, how should this be implemented?