HOW TO USE PROPERTY IN C#

Ankit Singh

Total Post:341

Points:2389
Posted by  Ankit Singh
C# 
C#
 409  View(s)
Ratings:
Rate this:
I want to use property in c# how to do this please help me.
  1. aditya kumar Patel

    Post:254

    Points:1810
    Re: How to use property in c#

    A property is a data member. in a class have multiple data members. which is easily access by class object. we can get and set a value of property.

    using System;
    namespace tutorialspoint
    {
        class Moters
        {
            private string engineno = "ADHG54578JAS";
            private string _modelname = "maruti suzuki swift";
     
            public string EngineNo
            {
                get
                {
                    return engineno;
                }
                set
                {
                    engineno = value;
                }
            }

          
            public string ModelName
            {
                get
                {
                    return _modelname;
                }
                set
                {
                    _modelname = value;
                }
            }

         
            public override string ToString()
            {
                return "EngineNo = " + EngineNo + ", ModelName = " + ModelName ;
            }
        }

        class Example
        {
            public static void Main()
            {
                Moters m = new Moters();        
                m.EngineNo = "2164DGAHSGD";
                m.ModelName = "safari storme ";
                Console.WriteLine("motors info: {0}", m);
                Console.WriteLine("motors info: {0}", m);
                Console.ReadKey();
            }
        }
    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!