using System; using System.Collections.Generic; using System.Text; namespace ClassExample { class Program { /**************************************** * this program shows how to create *a simple class and how to implement it *Steve Conger 10/72008 ******************************************/ static void Main(string[] args) { //declare a new instance of the class dog dog d = new dog(); //assign values to its properties //using the set part of the properties d.DogBreed = "chow"; d.DogSize = "medium"; d.DogName = "Fluffy"; //display the class content using the get method of the properties //call the method dogsound that returns the string "bark, bark" Console.WriteLine("{0} is a {1} of {2} size. She says {3}", d.DogName, d.DogBreed, d.DogSize, d.DogSound()); Console.ReadKey(); }//end main }//end class public class dog { /********************************* * this class describes a dog * and contains the method * Dog sound that retuns a string * usually the class is in a seperate file * but it can be in the same file ********************************/ //declare a private variable--a field that //describes dog private string breed; //encaspulate the field in a property //it is public so that it can be seen //outside the class public string DogBreed { //get allows a user of the class //to see the value of the breed variable get { return breed; } //set allows a user of the class //to assign a new value to the variable set { breed = value; } } //end property //assign and set properties for the rest //of the variables private string size; public string DogSize { get { return size; } set { size = value; } } //end property private string name; public string DogName { get { return name; } set { name = value; } } //end property //This is a public method //that returns a string public string DogSound() { return "bark, bark"; } //end method DogSound } //end class }//end namespace