A
A
ArrayPop2020-09-29 09:09:08
OOP
ArrayPop, 2020-09-29 09:09:08

How to pass an unknown class to a method with properties in c#?

An example of how you can pass an unknown class to a method.

public static void ReadData<T>() where T : new(){
T i = new T();
}


And this is not how it works anymore.
public static void ReadData<T>() where T : new(){
T i = new T{
params1 = "hello"
};
}

How to be in such a situation?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Korotenko, 2020-09-29
@firedragon

Pass not a class but an interface.

F
freeExec, 2020-09-29
@freeExec

Use dictionaries and store parameters there with text keys.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question