Static Versus Instance Members in C#
- By default, members are per instance
- Each instance gets its own fields
- Methods apply to a specific instance
- Static members are per type
- Static methods can’t access instance data
- No this variable in static methods
Static methods
public class Area { private int side; public Rectangle(int side) { this.side= side; } public void Area() { Console.WriteLine("Area output: " + Area.CalculateArea(this.side)); } public static int CalculateArea(int side) { return side* side; } }
Sample
0 comments:
Post a Comment