c# set base class to 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 int GetValue()
//    {
//        return this.value;
//    }
}

public class Example
{
    public static void Main(string[] args)
    {
        var b = new A.B();
        Console.WriteLine(b.GetValue());
    }
}
// The example displays the following output:
//       10

Example 2: Base class c#

class Motore:Veicoli
    { 
        public bool Cavalletto { get; set; }
       
        public Motore (String marca, String modello, int cilindrata, bool cavalletto): base (marca,modello,cilindrata)
        { 
            this.Cavalletto = cavalletto;
        }

        override
        public void Accelera(double velocitacorrente )
        {
            this.VelocitaCorrente += velocitacorrente;
        }
    }