Click here to Skip to main content
16,004,919 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: Uncommon behaviour Pin
Sandeep Mewara1-Jun-10 21:22
mveSandeep Mewara1-Jun-10 21:22 
GeneralRe: Uncommon behaviour Pin
m@dhu1-Jun-10 22:28
m@dhu1-Jun-10 22:28 
QuestionUrgent. Error in Fetching date field data from excel sheet Pin
cheguri1-Jun-10 18:58
cheguri1-Jun-10 18:58 
AnswerRe: Urgent. Error in Fetching date field data from excel sheet Pin
Sandeep Mewara1-Jun-10 19:42
mveSandeep Mewara1-Jun-10 19:42 
GeneralRe: Urgent. Error in Fetching date field data from excel sheet Pin
cheguri1-Jun-10 20:21
cheguri1-Jun-10 20:21 
QuestionProperties in .NET : Get and Set Pin
arithforu1-Jun-10 18:21
arithforu1-Jun-10 18:21 
AnswerRe: Properties in .NET : Get and Set Pin
Sandeep Mewara1-Jun-10 19:32
mveSandeep Mewara1-Jun-10 19:32 
AnswerRe: Properties in .NET : Get and Set Pin
walterhevedeich1-Jun-10 19:41
professionalwalterhevedeich1-Jun-10 19:41 
In order to understand them, you need to understand what an accessor means. The accessor of a property contains the executable statements associated with getting (reading or computing) or setting (writing) the property. The get and set keywords are accessors to a property. The code block for the get accessor is executed when the property is read; the code block for the set accessor is executed when the property is assigned a new value. A property without a set accessor is considered read-only. A property without a get accessor is considered write-only. A property that has both accessors is read-write. Here is a simple example(not the perfect example though Big Grin | :-D ) of a class that uses get and set.

class KgToLbsConverter
    {
        public double _qty;
        public bool _isKgs;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="qty">The amount of kgs/lbs</param>
        /// <param name="isKgs">determines if the quantity provided is in kgs or lbs</param>
        public KgToLbsConverter(double qty) 
        { 
            _qty = qty;            
        }
        public bool QuantityIsInKilograms
        {
            get { return _isKgs; } // the value of _isKgs is returned
            set { _isKgs = value; } // we set the value for _isKgs
        }
        //Properties with no set accessor are readonly
        public double Kilograms
        {
            get 
            {
                //If the quantity provided is in kilograms,it returns the quantity
                //Otherwise, it converts the quantity to kilograms before returning it.
                if (_isKgs) { return _qty; }
                else { return _qty * 2.20462262; };
            }            
        }

        public double Pounds
        {
            get
            {
                //If the quantity provided is in pounds,it returns the quantity
                //Otherwise, it converts the quantity to pounds before returning it.
                if (!_isKgs) { return _qty; }
                else { return _qty / 2.20462262; };
            }  
        }        
    }


and then in your main program, you can test the class with a code snippet something like this

KgToLbsConverter convert = new KgToLbsConverter(1);
convert.QuantityIsInKilograms = true;
//convert.Pounds will have a value of 2.20462262
//convert.Kilograms will have a value of 1


You can refer to the following links for more information.

Accessors - http://msdn.microsoft.com/en-us/library/aa287786%28VS.71%29.aspx

Properties - http://msdn.microsoft.com/en-us/library/w86s7x04.aspx

Get Keyword - http://msdn.microsoft.com/en-us/library/ms228503.aspx

Set Keyword - http://msdn.microsoft.com/en-us/library/ms228368.aspx
Walter

QuestionError sending Http Post Pin
Dot-Net-Dev1-Jun-10 17:35
Dot-Net-Dev1-Jun-10 17:35 
QuestionSearch Engine Optimization Hell !! Why the Google bot is not intelligent ! Pin
Nadia Monalisa1-Jun-10 10:33
Nadia Monalisa1-Jun-10 10:33 
AnswerRe: Search Engine Optimization Hell !! Why the Google bot is not intelligent ! Pin
T M Gray1-Jun-10 11:54
T M Gray1-Jun-10 11:54 
GeneralRe: Search Engine Optimization Hell !! Why the Google bot is not intelligent ! Pin
Nadia Monalisa1-Jun-10 12:20
Nadia Monalisa1-Jun-10 12:20 
GeneralListView with itemtemplate- Highlight selected row Pin
vjvjvjvj1-Jun-10 7:37
vjvjvjvj1-Jun-10 7:37 
GeneralRe: ListView with itemtemplate- Highlight selected row Pin
walterhevedeich1-Jun-10 18:38
professionalwalterhevedeich1-Jun-10 18:38 
GeneralRe: ListView with itemtemplate- Highlight selected row Pin
PunkIsNotDead4-Jun-10 8:20
PunkIsNotDead4-Jun-10 8:20 
Question[ASP.NET]Change the action of a form Pin
95ulisse1-Jun-10 7:19
95ulisse1-Jun-10 7:19 
AnswerRe: [ASP.NET]Change the action of a form Pin
Not Active1-Jun-10 9:09
mentorNot Active1-Jun-10 9:09 
AnswerRe: [ASP.NET]Change the action of a form Pin
95ulisse1-Jun-10 9:18
95ulisse1-Jun-10 9:18 
GeneralRe: [ASP.NET]Change the action of a form Pin
Not Active1-Jun-10 9:37
mentorNot Active1-Jun-10 9:37 
GeneralRe: [ASP.NET]Change the action of a form Pin
95ulisse1-Jun-10 23:45
95ulisse1-Jun-10 23:45 
GeneralRe: [ASP.NET]Change the action of a form Pin
Not Active2-Jun-10 2:27
mentorNot Active2-Jun-10 2:27 
QuestionSorted Checkboxlist Pin
vjvjvjvj1-Jun-10 4:17
vjvjvjvj1-Jun-10 4:17 
AnswerRe: Sorted Checkboxlist Pin
Sandeep Mewara1-Jun-10 6:40
mveSandeep Mewara1-Jun-10 6:40 
GeneralRe: Sorted Checkboxlist Pin
vjvjvjvj1-Jun-10 7:39
vjvjvjvj1-Jun-10 7:39 
QuestionW2k3 and Visual Studio 2010 Pin
Abrojus1-Jun-10 4:05
Abrojus1-Jun-10 4:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.