Technology Guruu

  • Home
  • Site Info
    • About Us
    • Disclaimer
    • Privacy Polacy
  • Home
  • Digital Marketing
    • SEO
    • SMM
    • SEM
  • Quotes
  • Technical
  • Java
  • .Net
    • C#.Net
    • ASP.Net
  • Keychains

Saturday, 2 April 2016

Brief description about properties

 Akansha     18:00:00     TechnicalQuestions     No comments   

Properties in C#.Net

hd wallpaper for properties
Properties
  • Property is a member of a class which we will use to assign the value to a variable as well as which we will use to retrieve the value from variable.
  • Property name and variable name should be same.
  • But variable name should start with small letter and property name should start with capital letter.
EX:
    eno->Variable name
    Eno->Property name

Syntax to Define a Property

<accessmodifier><return type><propertyname>
{
get->retrieving the value
}
{
set->assigning given value
}
}

Types Of Properties

1.Read Only Property

It will Contain only get accessor

2.Write Only Property

Contain only set accessor.

3..Read and Write Properties

Contain get accessor and set accessor

Properties are Two types

1.Instance Property
2.Static property

1.Instance Property

while defining a property if we did not use static keyword is called as instance property.
The purpose of instance property is to initialize and to retrieve values to instance variables.

2.Static Property

while defining if we have used static keyword is called as static property.
purpose of static property is o initialize as well as to retrive values from static variables.
EX:
namespace propertyex
{
Class Employee
{
int eno;
String ename;
int age;
static String cmpname;
internal int Eno
{
get
{
return eno;
}
set
{
eno=vaue;
}
}
internal string Ename
{
get
{
return ename;
}
set
{
ename=value;
}
}
internal int age
{
get
{
return age;
}
set
{
while(value<1||value>150)
{
Console.WriteLine("please enter valid age");
value=int.parse(Console.ReadLine());
}
age=value;
}
}
internal static string Cmpname
{
get
{
return cmpname;
}
set
{
cmpname=value;
}
}
}
class Program
{
void main()
{
Employee emp1=new Employee();
Console.WriteLine("enter your empno");
emp1.Eno=int.parse(console.ReadLine());
Console.WriteLine(" the empno is"+emp1.Eno);
Console.WriteLine("enter your empname");
emp1.Ename=int.parse(console.ReadLine());
Console.WriteLine("the empname is"+emp1.Ename);
Console.WriteLine("enter your age");
emp1.Age=int.parse(console.ReadLine());
Console.WriteLine("the age is"+emp1.Age);
Console.WriteLine("enter your company name");
Employee.CmpName=console.ReadLine();
Console.WriteLine("company name is"+Employee..CmpName);
Console.ReadLine();
}
}
}

Purpose Of Property

  • Whenever we want to assign the value to a class level variable or whenever we want to retrieve the value from class level variable fro outside the class we can go for property.
  • As well as whenever we want to perform validations while assigning the value to class level variable from outside the class we can use property.
Share With Your Friends in Social Media (Facebook, Twitter, Google Plus Etc...) if You Like Our Content And Feel Free To Comment.
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to XShare to Facebook
Newer Post Older Post Home

0 comments:

Post a Comment

Popular Posts

  • Brief description about Delegates
    Introduction about delegates and why delegates are came the main purpose of delegates how to useful and what are the advantages and disadv...
  • Missing My Friend Quotes : Friendship Day Quotes 2017
    Friends today my article about missing friends and moments with them. Here you are seen the best friendship quotes and some  feelings when...
  • Na Tanu Samjhawan Ki Song lyrics
    Na Tanu Samjhawan Ki Song Lyrics With English Translation Movie : Humpty Sharma ki Dulhaniya Song : Samjhawan Song Singer : Arijit ...
  • Detail Introduction about C#.Net
    Brief Introduction about C#.Net  Introduction C#.Net is the one of the Programming Language the .Net Framework also contains ano...
  • Love Failure Quotes and Sad valentines day Quotes
    We Love Someone is a easy process sometime takes long time to love someone love others within short period but anyway always love dependin...
  • Top 10 valentine's day Quotes and Greetings wishes
    All Lovers have Anxiety in Valentines day because it is a festival to all lovers in these they enjoy a lot and celebrate the Valentine...
  • Wonderful sayings about Life.
    I Believe Follow  Things(Life Quotes) I Believe I believe: ********** Believe in Life ********** That we don't have to chan...
  • Brief Description about Multicast Delegate
    Multicast delegate is an extension of normal delegate. It helps you to point more than one method at a single moment of time. Multicast ...
  • Letter B wallpapers and keychains for facebook
    In these we are Providing Letter B Wallpapers and awesome Key chains also Some Facebook Profile Pictures and cover photos also we are prov...
  • Best Good Afternoon wishes greetings and quotes
    Top Most Good Afternoon Wishes Good Afternoon wishes are gives a relaxation in afternoon time.This wishing can be done between 12 to 3 p...

Categories

  • Entertainment (67)
  • TechnicalQuestions (58)
  • Quotes (11)
  • C#.Net (8)
  • Java (8)
  • ValentinesDay (4)
  • SEO (3)
  • Home
  • About Us
  • Disclaimer
  • Privacy Policy
  • Sitemap

Copyright © 2015-2017 Good Friends 5.All Rights Reserved• And Our Sitemap • All Logos and Trademark Belongs To Their Respective Owners•