Instance methods in a class can access static data or call static methods. The instance method accesses static data or methods in the same way that other code does–by using the class name to qualify the data or method name.
Here’s an example, where the Dog.Bark instance method makes use of the private static Dog.FormatTheCreedmethod:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | // Static property -- one value for all dogspublic static string Creed { get; set; }// Private static method to format our Dog creedprivate static string FormatTheCreed(){ return string.Format("As dogs, we believe: {0}", Dog.Creed);}// Instance method, in which a Dog barkspublic void Bark(){ // Dump out my name and the universal Dog creed. Console.WriteLine("{0}: 'Woof'! (Creed: [{1}])", this.Name, Dog.FormatTheCreed());} |
Calling the Bark method:
1 2 3 4 5 | // Set static propertyDog.Creed = "We serve man";Dog kirby = new Dog("Kirby");kirby.Bark(); |

