Home  |  Contact         

Zrinity is the leader in enterprise-class email marketing management solutions and content management solutions for marketing professionals and developers worldwide.
Products Services Solutions Support Resources Partners Company
Java, PHP, CF Code Samples

Shows how to define a property in C# and make use of accessors

using System;

namespace MyNameSpace

{

      public class Foo

      {

            public Foo()

            {

                  x = 0;

            }

            private int x;

            public int X

            {

                  get

                  {

                        return x;

                  }

                  set

                  {

                        if (value > 0)

                        {

                              x = value;

                        }

                        else { x = 0; }

                  }

            }

            static void Main(string[] args)

            {

                  Foo f = new Foo();

                  f.X = 7;

                  Console.WriteLine("x = {0}", f.X);

                  f.X = -3;

                  Console.WriteLine("x = {0}", f.X);

            }

      }
}

This code will output
x = 7
x = 0



More Code Samples



  
home products services partners company support contact
Copyright 2006 © Zrinity Inc. All rights reserved.     View our privacy policy         September 7, 2010