C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
C# Auto-Implemented PropertiesC# 3.0 includes a concept of auto-implemented properties that requires no code inside get and set methods of the class properties. It makes code concise and readable. The C# compiler creates private fields correspond to the properties and are accessible using the get and set methods. Let's see an example of Auto-Implemented Properties. C# Auto-Implemented Properties Exampleusing System; using System.Collections.Generic; namespace CSharpFeatures { class Student { // Auto-implimented Properties public int ID { get; set; } public string Name { get; set; } public string Email { get; set; } } class AutoImplementedProperty { public static void Main(string[] args) { Student student = new Student(); // Setting properties student.ID = 101; student.Name = "Rahul Kumar"; student.Email = "rahul@example.com"; // Getting properties Console.WriteLine(student.ID); Console.WriteLine(student.Name); Console.WriteLine(student.Email); } } } Output: 101 Rahul Kumar [email protected]
Next TopicC# Dynamic Binding
|