In the simple example that you have given, there's really nothing
different. However, when you start developing more complex classes and
applications it will become apparent why using properties and accessor
methods is better. They allow you to validate the input data and reformat
the output data if necessary.
Start using properties and get used to them. You will see the benefit of
them as you gain more experience.
...Glenn
On Tue, Sep 16, 2008 at 3:35 AM, VIKAS GARG <[EMAIL PROTECTED]>wrote:
> What is diffrence in these two programs
>
>
> First Type
>
> using System;
> class MyClass
> {
> private static int x;
> public static int X
> {
> get
> {
> return x;
> }
> set
> {
> x = value;
> }
> }
> }
> class MyClient
> {
> public static void Main()
> {
> MyClass.X = 10;
> int xVal = MyClass.X;
> Console.WriteLine(xVal);//Displays 10
> Console.ReadKey();
> }
> }
>
>
>
>
>
>
>
> Second Type
>
> using System;
> class MyClass
> {
> private static int x;
> /*public static int X
> {
> get
> {
> return x;
> }
> set
> {
> x = value;
> }
> }*/
> }
> class MyClient
> {
> public static void Main()
> {
> //MyClass.X = 10;
> int xVal = 10;
> Console.WriteLine(xVal);//Displays 10
> Console.ReadKey();
> }
> }
>
>
>
> Both gives the same result
> How we use the properties in C#
> What is its use
> When we can do any tasks without using properties then why we use
> properties
> Here in my first progg I have created private variable and still able to
> work on my progg
> Please reply
> I am having big confusion in these
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web
Services,.NET Remoting" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://cm.megasolutions.net/forums/default.aspx
-~----------~----~----~----~------~----~------~--~---