.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> .NET Framework >> Post New QuestionBookmark and Share Subscribe to Forum

How to create and accessing Properties in c#

Posted By: Dhilip.R     Posted Date: November 27, 2010    Points:2   Category :.NET Framework

Hi,Experts

How to Create properties in C#?
and
How to access the Property variable or values in another class?

Thanks & Regards
Dhilip.R

Responses
Author: SureshM          Accepted Answer   
Posted Date: November 27, 2010     Points: 10   

// CREATE Properties

Public Class ClassName1
{

string strVar1;
string strVar2;

//This is the property of the class. var1 and var2
public string Var1
{
get
{
return strVa1;
}
set
{
strVar1 = value ;
}
}

public string Var2
{
get
{
return strVa2;
}
set
{
strVar2 =value;
}
}

}

//Access Properties

Public class ClassName2
{
//declare variables
string strValue1;
string strValue2;

// create object for ClassName1

ClassName1 objCl1=new ClassName1();

//Set the values to the properties of ClassName1

objCl1.Var1="Test Val";
objCl1.Var2="Vzalues";

//This for get the values from the properties of ClassName1
strValue1= objCl1.Var1;
strValue2= objCl1.Var2;


}



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend