I need an instance of the same class as another object, but I don't know the exact type. I have the following code.
abstract public class Row{
.
.
.
}
public class User : Row{
.
.
.
}
.
.
.
.
User test = new User();
Open(test);
.
.
.
private Row backup;
public static void Open(Row row){
.
.
.
db.backup = (Row) Activator.CreateInstance(row.GetType());
.
.
.
}
But when I run the program it generates NullReferenceException and I don't understand why... I tested it on the debugger and "row" is not null, everything seems right.
I googled it but no luck... however I read comments of people complaining about Activator.CreateInstance being too slow... is that true? what the best way to do this job?
backup
) from a static method (Open
). What is the exact exception you get (and on what line)User
object?db
null?