-->
int _number; public int Number { get { return _number; } set {_number = value; } }
using System; namespace ConsoleApplication1 { class Demo { int _number; public int Number { get { return _number; } set { _number = value; } } } class Program { static void Main() { Demo obj = new Demo(); obj.Number = 2; // set { } Console.WriteLine(obj.Number); // get { } } } }
public int Number { get; set;}
using System; namespace ConsoleApplication1 { class Demo { public int Number { get; set; } } class Program { static void Main() { Demo obj = new Demo(); obj.Number = 2; obj.Number *= 2; Console.WriteLine(obj.Number); } } }
Thanks for reading Asp.Net C# Property Examples (get, set)
Please do not enter any spam link in the comment box.
No comments:
Post a Comment
Please do not enter any spam link in the comment box.