GeekInterview.com
Series: Subject: Topic:
Question: 3 of 460

Properties in C#

What are properties in C#? What are the advantages of using Properties ?
Asked by: Velvizhi.Sadanah | Member Since Feb-2012 | Asked on: Feb 6th, 2012

View all questions by Velvizhi.Sadanah

Showing Answers 1 - 2 of 2 Answers

Properties are members of classes. They are also used in structs and interfaces. Properties are an extension of fields but they do not designate storage locations. Properties provide a flexible mechanism to read, write, or compute the values of private fields through accessors that read, write, or compute their values. Below example shows car Model and car Make properties for Car class

Code
  1. using System;
  2. class Car
  3. {
  4.     private string carModel ="Ambasador";
  5.     private int carMake = 0;
  6.  
  7.     public string Model
  8.     {
  9.         get
  10.         {
  11.            return carModel;
  12.         }
  13.         set
  14.         {
  15.            carModel = value;
  16.         }
  17.     }
  18.  
  19.     public string Make
  20.     {
  21.         get
  22.         {
  23.            return carMake;
  24.         }
  25.         set
  26.         {
  27.            carMake = value;
  28.         }
  29.     }
  30. }

Yes  3 Users have rated as useful.
  
Login to rate this answer.
Sivavt

Answered On : Mar 25th, 2012

View all answers by Sivavt

Properties combine the behavior of method & variable.

  
Login to rate this answer.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.