CSharp examples for Custom Type:Inheritance
A Base Class and a Class to Illustrate Its Use
using System;/*from w w w . java 2 s .co m*/ using System.Text; class Person { private string firstName; private string middleName; private string lastName ; private int age; // ToDo: Add properties to access the data members public Person() { } public Person(string fn, string ln) { firstName = fn; lastName = ln; } public Person(string fn, string mn, string ln) { firstName = fn; middleName = mn; lastName = ln; } public Person(string fn, string mn, string ln, int a) { firstName = fn; middleName = mn; lastName = ln; age = a; } public void displayAge() { Console.WriteLine("Age {0}", age); } public void displayFullName() { StringBuilder FullName = new StringBuilder(); FullName.Append(firstName); FullName.Append(" "); if( middleName != "" ) { FullName.Append(middleName[0]); FullName.Append(". "); } FullName.Append(lastName); Console.WriteLine(FullName); } } class NameApp { public static void Main() { Person me = new Person("A", "B", "C"); Person myWife = new Person("D", "E", "F", 21); me.displayFullName(); me.displayAge(); myWife.displayFullName(); myWife.displayAge(); } }