C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » .NET »

Properties in C#


Posted Date: 21 Nov 2008      Posted By: Sachin Arora      Member Level: Silver     Points: 1   Responses: 3



The following is giving error. Why.........


using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication79
{
class Program
{
int a;
int p;
public Program()
{
a = 10;
p = 12;
}
public int A
{
get
{
return a;
}
}
public int P
{
get
{
return p;
}
}
}
class MyClass
{
public static void Main()
{
Program o1 = new Program();
o1.A;
o1.P;
}
}
}





Responses

Author: Deepika Haridas    21 Nov 2008Member Level: DiamondRating: 2 out of 52 out of 5     Points: 6

class Program
{
int a;
int p;
public Program()
{
a = 10;
p = 12;
}
public int A
{
get
{
return a;
}
set
{ a = value; }
}
public int P
{
get
{
return p;
}
set { p = value; }
}
}

Program o1 = new Program();
MessageBox.Show(o1.A.ToString());
MessageBox.Show(o1.P.ToString());

you can use just o1.A



Thanks & Regards,
Deepika
Editor

If U want to shine like a SUN..First U have to burn like the SUN!!
Need a Guide? Join my mentor program..



Author: Deepika Haridas    21 Nov 2008Member Level: DiamondRating: 2 out of 52 out of 5     Points: 6

class Program
{
int a;
int p;
public Program()
{
a = 10;
p = 12;
}
public int A
{
get
{
return a;
}
set
{ a = value; }
}
public int P
{
get
{
return p;
}
set { p = value; }
}
}

Program o1 = new Program();
MessageBox.Show(o1.A.ToString());
MessageBox.Show(o1.P.ToString());

you cant use just o1.A



Thanks & Regards,
Deepika
Editor

If U want to shine like a SUN..First U have to burn like the SUN!!
Need a Guide? Join my mentor program..



Author: Happy Coder    21 Nov 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 3

try as below,
Also post the erro message too.

class MyClass
{
public static void Main()
{
Program o1 = new Program();
int a = o1.A;
int b = o1.P;
}
}

Geek is back.
____Happy_Coder____
If you feel this is helpful, RATE IT.



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : Need VB.Net Code !!!!!!!!!!!!! Urgent !!!!!!!!!!!!!!!!!!!!
Previous : Code Snippet
Return to Discussion Forum
Post New Message
Category: .NET

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use