I am using c# language for unity.
I need to use parent-child class for inventory system.
My script concept is below.
and i have error always at i marked it.
I know virtual-override can fix this thing but i just want to know that
Is this possible to use this concept?
public class A
{
public int a;
}
public class B : A
{
public int b;
}
public class C : A
{
public int c;
}
public class Main<T> where T : A, new()
{
public void callValue(T item)
{
if (item is B)
{
Console.WriteLine(item.a + "||" + ((B)item).b); // error cannot convert T to B;
}
if (item is C)
{
Console.WriteLine(item.a + "||" + ((C)item).c);
}
}
}