get base class from derived class c# code example
Example 1: acess base class in c#
using System;
public class A
{
private int value = 10;
public class B : A
{
public int GetValue()
{
return this.value;
}
}
}
public class C : A
{
}
public class Example
{
public static void Main(string[] args)
{
var b = new A.B();
Console.WriteLine(b.GetValue());
}
}
Example 2: how to get derived class from base class C#
class Base {
[...]
}
class Derived : Base {
[...]
}
Base baseInstance = new Derived();
Derived derivedFromInstance = (Derived)baseInstance;