Why this doesn’t accept a parameter of a class-type? What can I read about it? Here is my useless code
using System;
public class Class1
{
public int a = 5;
}
public class Class2
{
private readonly int num;
Class1 obj2 = new Class1();
public Class2(Class1 obj)
{
num = obj.a;
}
public Class2(string l) : this (Class1 obj2)
{
}
}
Your constructor takes an instance of
Class1, so you should use:You will probably also want to assign the constructor argument to your
obj2member instead of creating a new one: