<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FC_Sharp%2FClass_Interface%2FProperties</id>
		<title>Csharp/C Sharp/Class Interface/Properties - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FC_Sharp%2FClass_Interface%2FProperties"/>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/C_Sharp/Class_Interface/Properties&amp;action=history"/>
		<updated>2026-04-29T15:18:08Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/C_Sharp/Class_Interface/Properties&amp;diff=588&amp;oldid=prev</id>
		<title> в 15:31, 26 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/C_Sharp/Class_Interface/Properties&amp;diff=588&amp;oldid=prev"/>
				<updated>2010-05-26T15:31:18Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 15:31, 26 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/C_Sharp/Class_Interface/Properties&amp;diff=589&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/C_Sharp/Class_Interface/Properties&amp;diff=589&amp;oldid=prev"/>
				<updated>2010-05-26T11:39:02Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==access to a private field through a property==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
C# Programming Tips &amp;amp; Techniques&lt;br /&gt;
by Charles Wright, Kris Jamsa&lt;br /&gt;
Publisher: Osborne/McGraw-Hill (December 28, 2001)&lt;br /&gt;
ISBN: 0072193794&lt;br /&gt;
*/&lt;br /&gt;
//&lt;br /&gt;
//  Property.cs -- Demonstrates access to a private field through a property.&lt;br /&gt;
//                 Compile this program with the following command line:&lt;br /&gt;
//                     C:&amp;gt;csc Property.cs&lt;br /&gt;
//&lt;br /&gt;
namespace nsProperty&lt;br /&gt;
{&lt;br /&gt;
    using System;&lt;br /&gt;
    public class Property&lt;br /&gt;
    {&lt;br /&gt;
        const double radian = 57.29578;&lt;br /&gt;
        const double pi = 3.14159;&lt;br /&gt;
        int Angle&lt;br /&gt;
        {&lt;br /&gt;
            get&lt;br /&gt;
            {&lt;br /&gt;
                int angle = (int) (fAngle * radian + 0.5);&lt;br /&gt;
                angle = angle == 360 ? 0 : angle;&lt;br /&gt;
                return (angle);&lt;br /&gt;
            }&lt;br /&gt;
            set&lt;br /&gt;
            {&lt;br /&gt;
                double angle = (double) value / radian;&lt;br /&gt;
                if (angle &amp;lt; (2 * pi))&lt;br /&gt;
                {&lt;br /&gt;
                    fAngle = angle;&lt;br /&gt;
                    Console.WriteLine (&amp;quot;fAngle set to {0,0:F5}&amp;quot;, fAngle);&lt;br /&gt;
                }&lt;br /&gt;
                else&lt;br /&gt;
                {&lt;br /&gt;
                    Console.WriteLine (&amp;quot;fAngle not modified&amp;quot;);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        double fAngle = 0.0;   //  Angle in radians&lt;br /&gt;
        static public int Main (string [] args)&lt;br /&gt;
        {&lt;br /&gt;
            int angle;&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                angle = int.Parse (args[0]);&lt;br /&gt;
            }&lt;br /&gt;
            catch (IndexOutOfRangeException)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine (&amp;quot;usage: circle [angle in degrees]&amp;quot;);&lt;br /&gt;
                return (-1);&lt;br /&gt;
            }&lt;br /&gt;
            catch (FormatException)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine (&amp;quot;Please use a number value for the angle in degrees&amp;quot;);&lt;br /&gt;
                return (-1);&lt;br /&gt;
            }&lt;br /&gt;
            Property main = new Property();&lt;br /&gt;
            main.Angle = angle;&lt;br /&gt;
            Console.WriteLine (&amp;quot;The angle is {0} degrees&amp;quot;, main.Angle);&lt;br /&gt;
            return (0);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Add Length property to FailSoftArray==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
C#: The Complete Reference &lt;br /&gt;
by Herbert Schildt &lt;br /&gt;
Publisher: Osborne/McGraw-Hill (March 8, 2002)&lt;br /&gt;
ISBN: 0072134852&lt;br /&gt;
*/&lt;br /&gt;
// Add Length property to FailSoftArray. &lt;br /&gt;
 &lt;br /&gt;
using System; &lt;br /&gt;
 &lt;br /&gt;
class FailSoftArray {  &lt;br /&gt;
  int[] a; // reference to underlying array  &lt;br /&gt;
  int len; // length of array -- underlies Length property &lt;br /&gt;
 &lt;br /&gt;
  public bool errflag; // indicates outcome of last operation &lt;br /&gt;
   &lt;br /&gt;
  // Construct array given its size.  &lt;br /&gt;
  public FailSoftArray(int size) { &lt;br /&gt;
    a = new int[size]; &lt;br /&gt;
    len = size;  &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  // Read-only Length property. &lt;br /&gt;
  public int Length { &lt;br /&gt;
    get { &lt;br /&gt;
      return len; &lt;br /&gt;
    } &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  // This is the indexer for FailSoftArray. &lt;br /&gt;
  public int this[int index] { &lt;br /&gt;
    // This is the get accessor. &lt;br /&gt;
    get { &lt;br /&gt;
      if(ok(index)) { &lt;br /&gt;
        errflag = false; &lt;br /&gt;
        return a[index]; &lt;br /&gt;
      } else { &lt;br /&gt;
        errflag = true; &lt;br /&gt;
        return 0; &lt;br /&gt;
      } &lt;br /&gt;
    } &lt;br /&gt;
 &lt;br /&gt;
    // This is the set accessor &lt;br /&gt;
    set { &lt;br /&gt;
      if(ok(index)) { &lt;br /&gt;
        a[index] = value; &lt;br /&gt;
        errflag = false; &lt;br /&gt;
      } &lt;br /&gt;
      else errflag = true; &lt;br /&gt;
    } &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  // Return true if index is within bounds. &lt;br /&gt;
  private bool ok(int index) { &lt;br /&gt;
   if(index &amp;gt;= 0 &amp;amp; index &amp;lt; Length) return true; &lt;br /&gt;
   return false; &lt;br /&gt;
  } &lt;br /&gt;
}  &lt;br /&gt;
  &lt;br /&gt;
// Demonstrate the improved fail-soft array. &lt;br /&gt;
public class ImprovedFSDemo {  &lt;br /&gt;
  public static void Main() {  &lt;br /&gt;
    FailSoftArray fs = new FailSoftArray(5); &lt;br /&gt;
    int x; &lt;br /&gt;
 &lt;br /&gt;
    // can read Length &lt;br /&gt;
    for(int i=0; i &amp;lt; fs.Length; i++) &lt;br /&gt;
      fs[i] = i*10; &lt;br /&gt;
 &lt;br /&gt;
    for(int i=0; i &amp;lt; fs.Length; i++) { &lt;br /&gt;
      x = fs[i]; &lt;br /&gt;
      if(x != -1) Console.Write(x + &amp;quot; &amp;quot;); &lt;br /&gt;
    } &lt;br /&gt;
    Console.WriteLine(); &lt;br /&gt;
 &lt;br /&gt;
    // fs.Length = 10; // Error, illegal! &lt;br /&gt;
  } &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==A simple property example==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
C#: The Complete Reference &lt;br /&gt;
by Herbert Schildt &lt;br /&gt;
Publisher: Osborne/McGraw-Hill (March 8, 2002)&lt;br /&gt;
ISBN: 0072134852&lt;br /&gt;
*/&lt;br /&gt;
// A simple property example. &lt;br /&gt;
 &lt;br /&gt;
using System; &lt;br /&gt;
 &lt;br /&gt;
class SimpProp {  &lt;br /&gt;
  int prop; // field being managed by myprop &lt;br /&gt;
 &lt;br /&gt;
  public SimpProp() { prop = 0; } &lt;br /&gt;
 &lt;br /&gt;
  /* This is the property that supports access to &lt;br /&gt;
     the private instance variable prop.  It &lt;br /&gt;
     allows only positive values. */ &lt;br /&gt;
  public int myprop { &lt;br /&gt;
    get { &lt;br /&gt;
      return prop; &lt;br /&gt;
    } &lt;br /&gt;
    set { &lt;br /&gt;
      if(value &amp;gt;= 0) prop = value; &lt;br /&gt;
    }  &lt;br /&gt;
  } &lt;br /&gt;
}  &lt;br /&gt;
  &lt;br /&gt;
// Demonstrate a property. &lt;br /&gt;
public class PropertyDemo {  &lt;br /&gt;
  public static void Main() {  &lt;br /&gt;
    SimpProp ob = new SimpProp(); &lt;br /&gt;
 &lt;br /&gt;
    Console.WriteLine(&amp;quot;Original value of ob.myprop: &amp;quot; + ob.myprop); &lt;br /&gt;
 &lt;br /&gt;
    ob.myprop = 100; // assign value &lt;br /&gt;
    Console.WriteLine(&amp;quot;Value of ob.myprop: &amp;quot; + ob.myprop); &lt;br /&gt;
 &lt;br /&gt;
    // Can&amp;quot;t assign negative value to prop &lt;br /&gt;
    Console.WriteLine(&amp;quot;Attempting to -10 assign to ob.myprop&amp;quot;); &lt;br /&gt;
    ob.myprop = -10; &lt;br /&gt;
    Console.WriteLine(&amp;quot;Value of ob.myprop: &amp;quot; + ob.myprop); &lt;br /&gt;
  } &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Convert errflag into a property==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
C#: The Complete Reference &lt;br /&gt;
by Herbert Schildt &lt;br /&gt;
Publisher: Osborne/McGraw-Hill (March 8, 2002)&lt;br /&gt;
ISBN: 0072134852&lt;br /&gt;
*/&lt;br /&gt;
// Convert errflag into a property. &lt;br /&gt;
 &lt;br /&gt;
using System; &lt;br /&gt;
 &lt;br /&gt;
class FailSoftArray {  &lt;br /&gt;
  int[] a; // reference to underlying array  &lt;br /&gt;
  int len; // length of array &lt;br /&gt;
 &lt;br /&gt;
  bool errflag; // now private &lt;br /&gt;
   &lt;br /&gt;
  // Construct array given its size.  &lt;br /&gt;
  public FailSoftArray(int size) { &lt;br /&gt;
    a = new int[size]; &lt;br /&gt;
    len = size;  &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  // Read-only Length property. &lt;br /&gt;
  public int Length { &lt;br /&gt;
    get { &lt;br /&gt;
      return len; &lt;br /&gt;
    } &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  // Read-only Error property. &lt;br /&gt;
  public bool Error { &lt;br /&gt;
    get { &lt;br /&gt;
      return errflag; &lt;br /&gt;
    } &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  // This is the indexer for FailSoftArray. &lt;br /&gt;
  public int this[int index] { &lt;br /&gt;
    // This is the get accessor. &lt;br /&gt;
    get { &lt;br /&gt;
      if(ok(index)) { &lt;br /&gt;
        errflag = false; &lt;br /&gt;
        return a[index]; &lt;br /&gt;
      } else { &lt;br /&gt;
        errflag = true; &lt;br /&gt;
        return 0; &lt;br /&gt;
      } &lt;br /&gt;
    } &lt;br /&gt;
 &lt;br /&gt;
    // This is the set accessor &lt;br /&gt;
    set { &lt;br /&gt;
      if(ok(index)) { &lt;br /&gt;
        a[index] = value; &lt;br /&gt;
        errflag = false; &lt;br /&gt;
      } &lt;br /&gt;
      else errflag = true; &lt;br /&gt;
    } &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  // Return true if index is within bounds. &lt;br /&gt;
  private bool ok(int index) { &lt;br /&gt;
   if(index &amp;gt;= 0 &amp;amp; index &amp;lt; Length) return true; &lt;br /&gt;
   return false; &lt;br /&gt;
  } &lt;br /&gt;
}  &lt;br /&gt;
  &lt;br /&gt;
// Demonstrate the improved fail-soft array. &lt;br /&gt;
public class FinalFSDemo {  &lt;br /&gt;
  public static void Main() {  &lt;br /&gt;
    FailSoftArray fs = new FailSoftArray(5); &lt;br /&gt;
 &lt;br /&gt;
    // use Error property &lt;br /&gt;
    for(int i=0; i &amp;lt; fs.Length + 1; i++) { &lt;br /&gt;
      fs[i] = i*10; &lt;br /&gt;
      if(fs.Error)  &lt;br /&gt;
        Console.WriteLine(&amp;quot;Error with index &amp;quot; + i); &lt;br /&gt;
    } &lt;br /&gt;
 &lt;br /&gt;
  } &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Define properties for class==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
Learning C# &lt;br /&gt;
by Jesse Liberty&lt;br /&gt;
Publisher: O&amp;quot;Reilly &lt;br /&gt;
ISBN: 0596003765&lt;br /&gt;
*/&lt;br /&gt;
 using System;&lt;br /&gt;
 namespace Properties&lt;br /&gt;
 {&lt;br /&gt;
     class Time&lt;br /&gt;
     {&lt;br /&gt;
         // private member variables&lt;br /&gt;
         private int year;&lt;br /&gt;
         private int month;&lt;br /&gt;
         private int date;&lt;br /&gt;
         private int hour;&lt;br /&gt;
         private int minute;&lt;br /&gt;
         private int second;&lt;br /&gt;
         // create a property&lt;br /&gt;
         public int Hour&lt;br /&gt;
         {&lt;br /&gt;
             get&lt;br /&gt;
             {&lt;br /&gt;
                 return hour;&lt;br /&gt;
             }&lt;br /&gt;
             set&lt;br /&gt;
             {&lt;br /&gt;
                 hour = value;&lt;br /&gt;
             }&lt;br /&gt;
         }&lt;br /&gt;
         // public accessor methods&lt;br /&gt;
         public void DisplayCurrentTime()&lt;br /&gt;
         {&lt;br /&gt;
             System.Console.WriteLine(&lt;br /&gt;
                 &amp;quot;Time: {0}/{1}/{2} {3}:{4}:{5}&amp;quot;,&lt;br /&gt;
                 month, date, year, hour, minute, second);&lt;br /&gt;
         }&lt;br /&gt;
&lt;br /&gt;
         // constructors&lt;br /&gt;
         public Time(System.DateTime dt)&lt;br /&gt;
         {&lt;br /&gt;
             year =      dt.Year;&lt;br /&gt;
             month =     dt.Month;&lt;br /&gt;
             date =      dt.Day;&lt;br /&gt;
             hour =      dt.Hour;&lt;br /&gt;
             minute =    dt.Minute;&lt;br /&gt;
             second =    dt.Second;&lt;br /&gt;
         }&lt;br /&gt;
&lt;br /&gt;
    }&lt;br /&gt;
    public class PropertiesTester&lt;br /&gt;
    {&lt;br /&gt;
       public void Run()&lt;br /&gt;
       {&lt;br /&gt;
           System.DateTime currentTime = System.DateTime.Now;&lt;br /&gt;
           Time t = new Time(currentTime);&lt;br /&gt;
           t.DisplayCurrentTime();&lt;br /&gt;
           // access the hour to a local variable&lt;br /&gt;
           int theHour = t.Hour;&lt;br /&gt;
           // display it&lt;br /&gt;
           System.Console.WriteLine(&amp;quot;Retrieved the hour: {0}&amp;quot;,&lt;br /&gt;
               theHour);&lt;br /&gt;
           // increment it&lt;br /&gt;
           theHour++;&lt;br /&gt;
           // reassign the incremented value back through&lt;br /&gt;
           // the property&lt;br /&gt;
           t.Hour = theHour;&lt;br /&gt;
           // display the property&lt;br /&gt;
           System.Console.WriteLine(&amp;quot;Updated the hour: {0}&amp;quot;, t.Hour);&lt;br /&gt;
       }&lt;br /&gt;
       [STAThread]&lt;br /&gt;
       static void Main()&lt;br /&gt;
       {&lt;br /&gt;
          PropertiesTester t = new PropertiesTester();&lt;br /&gt;
          t.Run();&lt;br /&gt;
       }&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Delegates as Static Properties==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
A Programmer&amp;quot;s Introduction to C# (Second Edition)&lt;br /&gt;
by Eric Gunnerson&lt;br /&gt;
Publisher: Apress  L.P.&lt;br /&gt;
ISBN: 1-893115-62-3&lt;br /&gt;
*/&lt;br /&gt;
// 22 - Delegates\Delegates as Static Properties&lt;br /&gt;
// copyright 2000 Eric Gunnerson&lt;br /&gt;
using System;&lt;br /&gt;
class Container&lt;br /&gt;
{&lt;br /&gt;
    public delegate int CompareItemsCallback(object obj1, object obj2);&lt;br /&gt;
    public void SortItems(CompareItemsCallback compare)&lt;br /&gt;
    {&lt;br /&gt;
        // not a real sort, just shows what the&lt;br /&gt;
        // inner loop code might do&lt;br /&gt;
        int x = 0;&lt;br /&gt;
        int y = 1;&lt;br /&gt;
        object    item1 = arr[x];&lt;br /&gt;
        object item2 = arr[y];&lt;br /&gt;
        int order = compare(item1, item2);&lt;br /&gt;
    }&lt;br /&gt;
    object[]    arr;    // items in the collection&lt;br /&gt;
}&lt;br /&gt;
class Employee&lt;br /&gt;
{&lt;br /&gt;
    Employee(string name, int id)&lt;br /&gt;
    {&lt;br /&gt;
        this.name = name;&lt;br /&gt;
        this.id = id;&lt;br /&gt;
    }&lt;br /&gt;
    public static Container.rupareItemsCallback SortByName&lt;br /&gt;
    {&lt;br /&gt;
        get&lt;br /&gt;
        {&lt;br /&gt;
            return(new Container.rupareItemsCallback(CompareName));&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    public static Container.rupareItemsCallback SortById&lt;br /&gt;
    {&lt;br /&gt;
        get&lt;br /&gt;
        {&lt;br /&gt;
            return(new Container.rupareItemsCallback(CompareId));&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    static int CompareName(object obj1, object obj2)&lt;br /&gt;
    {&lt;br /&gt;
        Employee emp1 = (Employee) obj1;&lt;br /&gt;
        Employee emp2 = (Employee) obj2;&lt;br /&gt;
        return(String.rupare(emp1.name, emp2.name));&lt;br /&gt;
    }&lt;br /&gt;
    static int CompareId(object obj1, object obj2)&lt;br /&gt;
    {&lt;br /&gt;
        Employee emp1 = (Employee) obj1;&lt;br /&gt;
        Employee emp2 = (Employee) obj2;&lt;br /&gt;
        &lt;br /&gt;
        if (emp1.id &amp;gt; emp2.id)&lt;br /&gt;
        return(1);&lt;br /&gt;
        if (emp1.id &amp;lt; emp2.id)&lt;br /&gt;
        return(-1);&lt;br /&gt;
        else&lt;br /&gt;
        return(0);&lt;br /&gt;
    }&lt;br /&gt;
    string    name;&lt;br /&gt;
    int    id;&lt;br /&gt;
}&lt;br /&gt;
public class DelegatesasStaticProperties&lt;br /&gt;
{&lt;br /&gt;
    public static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        Container employees = new Container();&lt;br /&gt;
        // create and add some employees here&lt;br /&gt;
        &lt;br /&gt;
        employees.SortItems(Employee.SortByName);&lt;br /&gt;
        // employees is now sorted by name&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Demonstrates the use of properties to control how values are saved in fields==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
C# Programming Tips &amp;amp; Techniques&lt;br /&gt;
by Charles Wright, Kris Jamsa&lt;br /&gt;
Publisher: Osborne/McGraw-Hill (December 28, 2001)&lt;br /&gt;
ISBN: 0072193794&lt;br /&gt;
*/&lt;br /&gt;
//  Rect.cs - Demonstrates the use of properties to control how values are&lt;br /&gt;
//            saved in fields&lt;br /&gt;
//&lt;br /&gt;
//            This is a Visual Studio project. To compile outside of Visual&lt;br /&gt;
//            Studio, use the following command line:&lt;br /&gt;
//                C:&amp;gt;csc rect.cs&lt;br /&gt;
//&lt;br /&gt;
using System;&lt;br /&gt;
using System.Drawing;&lt;br /&gt;
namespace nsRect&lt;br /&gt;
{&lt;br /&gt;
  struct POINT&lt;br /&gt;
  {&lt;br /&gt;
    public POINT (int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
      this.cx = x;&lt;br /&gt;
      this.cy = y;&lt;br /&gt;
    }&lt;br /&gt;
    public int cx;&lt;br /&gt;
    public int cy;&lt;br /&gt;
    public override string ToString ()&lt;br /&gt;
    {&lt;br /&gt;
      return (String.Format (&amp;quot;({0}, {1})&amp;quot;, cx, cy));&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  struct RECT&lt;br /&gt;
  {&lt;br /&gt;
    public RECT (Rectangle rc)&lt;br /&gt;
    {&lt;br /&gt;
      m_UpperLeft.cx = rc.X;&lt;br /&gt;
      m_UpperLeft.cy = rc.Y;&lt;br /&gt;
      m_LowerRight.cx = rc.X + rc.Width;&lt;br /&gt;
      m_LowerRight.cy = rc.Y + rc.Height;&lt;br /&gt;
    }&lt;br /&gt;
    // Define constructors&lt;br /&gt;
    public RECT (POINT pt1, POINT pt2)&lt;br /&gt;
    {&lt;br /&gt;
      m_UpperLeft = pt1;&lt;br /&gt;
      m_LowerRight = pt2;&lt;br /&gt;
    }&lt;br /&gt;
    public RECT (int x1, int y1, int x2, int y2)&lt;br /&gt;
    {&lt;br /&gt;
      m_UpperLeft.cx = x1;&lt;br /&gt;
      m_UpperLeft.cy = y1;&lt;br /&gt;
      m_LowerRight.cx = x2;&lt;br /&gt;
      m_LowerRight.cy = y2;&lt;br /&gt;
    }&lt;br /&gt;
    public RECT (POINT pt1, int Width, int Height)&lt;br /&gt;
    {&lt;br /&gt;
      m_UpperLeft.cx = pt1.cx;&lt;br /&gt;
      m_UpperLeft.cy = pt1.cy;&lt;br /&gt;
      m_LowerRight.cx = pt1.cx + Width;&lt;br /&gt;
      m_LowerRight.cy = pt1.cy + Height;&lt;br /&gt;
    }&lt;br /&gt;
    // Property to get and set the upper left point&lt;br /&gt;
    public POINT UpperLeft&lt;br /&gt;
    {&lt;br /&gt;
      get {return (m_UpperLeft);}&lt;br /&gt;
      set {m_UpperLeft = value;}&lt;br /&gt;
    }&lt;br /&gt;
    // Property to get and set the lower right point&lt;br /&gt;
    public POINT LowerRight&lt;br /&gt;
    {&lt;br /&gt;
      get {return (m_LowerRight);}&lt;br /&gt;
      set {m_LowerRight = value;}&lt;br /&gt;
    }&lt;br /&gt;
    // Property to return a normalized System.Drawing.ectangle object&lt;br /&gt;
    public System.Drawing.Rectangle Rectangle&lt;br /&gt;
    {&lt;br /&gt;
      get&lt;br /&gt;
      {&lt;br /&gt;
        RECT rc = Normal;&lt;br /&gt;
        return (new Rectangle (rc.UpperLeft.cx, rc.UpperLeft.cy,&lt;br /&gt;
          rc.LowerRight.cx - rc.UpperLeft.cx,&lt;br /&gt;
          rc.LowerRight.cy - rc.UpperLeft.cy));&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    // Property to return a normalized copy of this rectangle&lt;br /&gt;
    public RECT Normal&lt;br /&gt;
    {&lt;br /&gt;
      get&lt;br /&gt;
      {&lt;br /&gt;
        return (new RECT (&lt;br /&gt;
          Math.Min (m_LowerRight.cx, m_UpperLeft.cx),&lt;br /&gt;
          Math.Min (m_LowerRight.cy, m_UpperLeft.cy),&lt;br /&gt;
          Math.Max (m_LowerRight.cx, m_UpperLeft.cx),&lt;br /&gt;
          Math.Max (m_LowerRight.cy, m_UpperLeft.cy))&lt;br /&gt;
          );&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    private POINT m_UpperLeft;&lt;br /&gt;
    private POINT m_LowerRight;&lt;br /&gt;
    public override string ToString()&lt;br /&gt;
    {&lt;br /&gt;
      return (String.Format (&amp;quot;Upper left = {0}; Lower right = {1}&amp;quot;,&lt;br /&gt;
        m_UpperLeft, m_LowerRight));&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  public class Rect&lt;br /&gt;
  {&lt;br /&gt;
    static public void Main ()&lt;br /&gt;
    {&lt;br /&gt;
      // Define a &amp;quot;normal&amp;quot; rectangle&lt;br /&gt;
      POINT pt1 = new POINT (-10,30);&lt;br /&gt;
      POINT pt2 = new POINT (100, 100);&lt;br /&gt;
      RECT rc = new RECT (pt1, pt2);&lt;br /&gt;
      Console.WriteLine (&amp;quot;RECT: &amp;quot; + rc);&lt;br /&gt;
      Console.WriteLine (&amp;quot;Normal: &amp;quot; + rc.Normal);&lt;br /&gt;
      Console.WriteLine (&amp;quot;Rectangle: &amp;quot; + rc.Rectangle + &amp;quot;\n&amp;quot;);&lt;br /&gt;
      // Define a rectangle with normal x but not y&lt;br /&gt;
      pt1.cx = 100;&lt;br /&gt;
      pt1.cy = 50;&lt;br /&gt;
      pt2.cx = 200;&lt;br /&gt;
      pt2.cy = 20;&lt;br /&gt;
      rc.UpperLeft = pt1;&lt;br /&gt;
      rc.LowerRight = pt2;&lt;br /&gt;
      Console.WriteLine (&amp;quot;RECT: &amp;quot; + rc);&lt;br /&gt;
      Console.WriteLine (&amp;quot;Normal: &amp;quot; + rc.Normal);&lt;br /&gt;
      Console.WriteLine (&amp;quot;Rectangle: &amp;quot; + rc.Rectangle + &amp;quot;\n&amp;quot;);&lt;br /&gt;
      // Define a rectangle with normal y but not x&lt;br /&gt;
      pt1.cx = 200;&lt;br /&gt;
      pt1.cy = 50;&lt;br /&gt;
      pt2.cx = 100;&lt;br /&gt;
      pt2.cy = 80;&lt;br /&gt;
      rc.UpperLeft = pt1;&lt;br /&gt;
      rc.LowerRight = pt2;&lt;br /&gt;
      Console.WriteLine (&amp;quot;RECT: &amp;quot; + rc);&lt;br /&gt;
      Console.WriteLine (&amp;quot;Normal: &amp;quot; + rc.Normal);&lt;br /&gt;
      Console.WriteLine (&amp;quot;Rectangle: &amp;quot; + rc.Rectangle + &amp;quot;\n&amp;quot;);&lt;br /&gt;
      // Define a rectangle with both values of upper left greater than the lower y&lt;br /&gt;
      pt1.cx = 225;&lt;br /&gt;
      pt1.cy = 180;&lt;br /&gt;
      pt2.cx = 25;&lt;br /&gt;
      pt2.cy = 35;&lt;br /&gt;
      rc.UpperLeft = pt1;&lt;br /&gt;
      rc.LowerRight = pt2;&lt;br /&gt;
      Console.WriteLine (&amp;quot;RECT: &amp;quot; + rc);&lt;br /&gt;
      Console.WriteLine (&amp;quot;Normal: &amp;quot; + rc.Normal);&lt;br /&gt;
      Console.WriteLine (&amp;quot;Rectangle: &amp;quot; + rc.Rectangle + &amp;quot;\n&amp;quot;);&lt;br /&gt;
      // Define a rectangle with points equal&lt;br /&gt;
      pt1.cx = 75;&lt;br /&gt;
      pt1.cy = 150;&lt;br /&gt;
      pt2.cx = 75;&lt;br /&gt;
      pt2.cy = 150;&lt;br /&gt;
      rc.UpperLeft = pt1;&lt;br /&gt;
      rc.LowerRight = pt2;&lt;br /&gt;
      Console.WriteLine (&amp;quot;RECT: &amp;quot; + rc);&lt;br /&gt;
      Console.WriteLine (&amp;quot;Normal: &amp;quot; + rc.Normal);&lt;br /&gt;
      Console.WriteLine (&amp;quot;Rectangle: &amp;quot; + rc.Rectangle + &amp;quot;\n&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==enum based attribute==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
&lt;br /&gt;
using System;&lt;br /&gt;
public enum RemoteServers&lt;br /&gt;
{&lt;br /&gt;
    A,&lt;br /&gt;
    B,&lt;br /&gt;
    C&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
public class RemoteObjectAttribute : Attribute&lt;br /&gt;
{&lt;br /&gt;
    public RemoteObjectAttribute(RemoteServers Server)&lt;br /&gt;
    {&lt;br /&gt;
        this.server = Server;&lt;br /&gt;
    }&lt;br /&gt;
   &lt;br /&gt;
    protected RemoteServers server;&lt;br /&gt;
    public string Server&lt;br /&gt;
    {&lt;br /&gt;
        get &lt;br /&gt;
        { &lt;br /&gt;
            return RemoteServers.GetName(&lt;br /&gt;
                typeof(RemoteServers), this.server);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
[RemoteObject(RemoteServers.C)]&lt;br /&gt;
class MyRemotableClass&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
class Test&lt;br /&gt;
{&lt;br /&gt;
    [STAThread]&lt;br /&gt;
    static void Main(string[] args)&lt;br /&gt;
    {&lt;br /&gt;
        Type type = typeof(MyRemotableClass);&lt;br /&gt;
        foreach (Attribute attr in type.GetCustomAttributes(true))&lt;br /&gt;
        {&lt;br /&gt;
            RemoteObjectAttribute remoteAttr = attr as RemoteObjectAttribute;&lt;br /&gt;
            if (null != remoteAttr)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(remoteAttr.Server);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Error handling in property setter validating==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
&lt;br /&gt;
using System;&lt;br /&gt;
public class Employee {&lt;br /&gt;
    private int prop_age;&lt;br /&gt;
    public int age {&lt;br /&gt;
        set {&lt;br /&gt;
            if (value &amp;lt; 0 || value &amp;gt; 120) {&lt;br /&gt;
                throw new ApplicationException(&amp;quot;Not valid age!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            prop_age = value;&lt;br /&gt;
        }&lt;br /&gt;
        get {&lt;br /&gt;
            return prop_age;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Illustrates the use of a property==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
Mastering Visual C# .NET&lt;br /&gt;
by Jason Price, Mike Gunderloy&lt;br /&gt;
Publisher: Sybex;&lt;br /&gt;
ISBN: 0782129110&lt;br /&gt;
*/&lt;br /&gt;
/*&lt;br /&gt;
  Example6_4.cs illustrates the use of a property&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
// declare the Car class&lt;br /&gt;
class Car&lt;br /&gt;
{&lt;br /&gt;
  // declare a private field&lt;br /&gt;
  private string make;&lt;br /&gt;
  // declare a property&lt;br /&gt;
  public string Make&lt;br /&gt;
  {&lt;br /&gt;
    get&lt;br /&gt;
    {&lt;br /&gt;
      return make;&lt;br /&gt;
    }&lt;br /&gt;
    set&lt;br /&gt;
    {&lt;br /&gt;
      make = value;&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public class Example6_4&lt;br /&gt;
{&lt;br /&gt;
  public static void Main()&lt;br /&gt;
  {&lt;br /&gt;
    // create a Car object&lt;br /&gt;
    System.Console.WriteLine(&amp;quot;Creating a Car object&amp;quot;);&lt;br /&gt;
    Car myCar = new Car();&lt;br /&gt;
    // set the Car Make&lt;br /&gt;
    System.Console.WriteLine(&amp;quot;Setting the Car object&amp;quot;s Make property to Porsche&amp;quot;);&lt;br /&gt;
    myCar.Make = &amp;quot;Porsche&amp;quot;;&lt;br /&gt;
    System.Console.WriteLine(&amp;quot;myCar.Make = &amp;quot; + myCar.Make);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Override Properties==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections;&lt;br /&gt;
   &lt;br /&gt;
abstract class Employee&lt;br /&gt;
{&lt;br /&gt;
    protected Employee(int employeeId, int hoursWorked)&lt;br /&gt;
    {&lt;br /&gt;
        this.employeeId = employeeId;&lt;br /&gt;
        HoursWorked = hoursWorked;&lt;br /&gt;
    }&lt;br /&gt;
   &lt;br /&gt;
    protected int employeeId;&lt;br /&gt;
    public int EmployeeId&lt;br /&gt;
    {&lt;br /&gt;
        get { return employeeId; }&lt;br /&gt;
    }&lt;br /&gt;
   &lt;br /&gt;
    protected int HoursWorked;&lt;br /&gt;
   &lt;br /&gt;
    protected double hourlyCost = -1; // dummy init value&lt;br /&gt;
    public abstract double HourlyCost&lt;br /&gt;
    { &lt;br /&gt;
        get;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
class ContractEmployee : Employee&lt;br /&gt;
{&lt;br /&gt;
    public ContractEmployee(int employeeId, double hourlyWage,&lt;br /&gt;
        int hoursWorked)&lt;br /&gt;
        : base(employeeId, hoursWorked)&lt;br /&gt;
    {&lt;br /&gt;
        HourlyWage = hourlyWage;&lt;br /&gt;
    }&lt;br /&gt;
   &lt;br /&gt;
    protected double HourlyWage;&lt;br /&gt;
    public override double HourlyCost&lt;br /&gt;
    { &lt;br /&gt;
        get &lt;br /&gt;
        { return HourlyWage; }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
class SalariedEmployee : Employee&lt;br /&gt;
{&lt;br /&gt;
    public SalariedEmployee(int employeeId, double salary,&lt;br /&gt;
        int hoursWorked)&lt;br /&gt;
        : base(employeeId, hoursWorked)&lt;br /&gt;
    {&lt;br /&gt;
        Salary = salary;&lt;br /&gt;
    }&lt;br /&gt;
   &lt;br /&gt;
    protected double Salary;&lt;br /&gt;
    public override double HourlyCost&lt;br /&gt;
    { &lt;br /&gt;
        get &lt;br /&gt;
        { &lt;br /&gt;
            return (Salary / 52) / HoursWorked; &lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
class OverrideProperties&lt;br /&gt;
{&lt;br /&gt;
    public static ArrayList employees = new ArrayList();&lt;br /&gt;
 &lt;br /&gt;
    public static void PrintEmployeesHourlyCostToCompany()&lt;br /&gt;
    {&lt;br /&gt;
        foreach (Employee employee in employees)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;{0} employee (id={1}) costs {2}&amp;quot; +&lt;br /&gt;
                &amp;quot; per hour&amp;quot;, employee, employee.EmployeeId,&lt;br /&gt;
                employee.HourlyCost);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
   &lt;br /&gt;
    public static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        ContractEmployee c  = new ContractEmployee(1, 50, 40);&lt;br /&gt;
        employees.Add(c);&lt;br /&gt;
   &lt;br /&gt;
        SalariedEmployee s =&lt;br /&gt;
            new SalariedEmployee(2, 100000, 65);&lt;br /&gt;
        employees.Add(s);&lt;br /&gt;
   &lt;br /&gt;
        PrintEmployeesHourlyCostToCompany();&lt;br /&gt;
   &lt;br /&gt;
        Console.ReadLine();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Properties Accessors==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
A Programmer&amp;quot;s Introduction to C# (Second Edition)&lt;br /&gt;
by Eric Gunnerson&lt;br /&gt;
Publisher: Apress  L.P.&lt;br /&gt;
ISBN: 1-893115-62-3&lt;br /&gt;
*/&lt;br /&gt;
// 18 - Properties\Accessors&lt;br /&gt;
// copyright 2000 Eric Gunnerson&lt;br /&gt;
public class PropertiesAccessors&lt;br /&gt;
{&lt;br /&gt;
    private string name;&lt;br /&gt;
    &lt;br /&gt;
    public string Name&lt;br /&gt;
    {&lt;br /&gt;
        get &lt;br /&gt;
        {&lt;br /&gt;
            return name;&lt;br /&gt;
        }&lt;br /&gt;
        set &lt;br /&gt;
        {&lt;br /&gt;
            name = value;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Properties: Side Effects When Setting Values==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
A Programmer&amp;quot;s Introduction to C# (Second Edition)&lt;br /&gt;
by Eric Gunnerson&lt;br /&gt;
Publisher: Apress  L.P.&lt;br /&gt;
ISBN: 1-893115-62-3&lt;br /&gt;
*/&lt;br /&gt;
// 18 - Properties\Side Effects When Setting Values&lt;br /&gt;
// copyright 2000 Eric Gunnerson&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections;&lt;br /&gt;
class Basket&lt;br /&gt;
{&lt;br /&gt;
    internal void UpdateTotal()&lt;br /&gt;
    {&lt;br /&gt;
        total = 0;&lt;br /&gt;
        foreach (BasketItem item in items)&lt;br /&gt;
        {&lt;br /&gt;
            total += item.Total;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    ArrayList    items = new ArrayList();&lt;br /&gt;
    Decimal    total;&lt;br /&gt;
}&lt;br /&gt;
public class BasketItem&lt;br /&gt;
{&lt;br /&gt;
    BasketItem(Basket basket)&lt;br /&gt;
    {&lt;br /&gt;
        this.basket = basket;&lt;br /&gt;
    }&lt;br /&gt;
    public int Quantity&lt;br /&gt;
    {&lt;br /&gt;
        get&lt;br /&gt;
        {&lt;br /&gt;
            return(quantity);&lt;br /&gt;
        }&lt;br /&gt;
        set&lt;br /&gt;
        {&lt;br /&gt;
            quantity = value;&lt;br /&gt;
            basket.UpdateTotal();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    public Decimal Price&lt;br /&gt;
    {&lt;br /&gt;
        get&lt;br /&gt;
        {&lt;br /&gt;
            return(price);&lt;br /&gt;
        }&lt;br /&gt;
        set&lt;br /&gt;
        {&lt;br /&gt;
            price = value;&lt;br /&gt;
            basket.UpdateTotal();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    public Decimal Total&lt;br /&gt;
    {&lt;br /&gt;
        get&lt;br /&gt;
        {&lt;br /&gt;
            // volume discount; 10% if 10 or more are purchased&lt;br /&gt;
            if (quantity &amp;gt;= 10)&lt;br /&gt;
            return(quantity * price * 0.90m);&lt;br /&gt;
            else&lt;br /&gt;
            return(quantity * price); &lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    int        quantity;     // count of the item&lt;br /&gt;
    Decimal    price;        // price of the item&lt;br /&gt;
    Basket     basket;       // reference back to the basket&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Properties:Static Properties==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
A Programmer&amp;quot;s Introduction to C# (Second Edition)&lt;br /&gt;
by Eric Gunnerson&lt;br /&gt;
Publisher: Apress  L.P.&lt;br /&gt;
ISBN: 1-893115-62-3&lt;br /&gt;
*/&lt;br /&gt;
// 18 - Properties\Static Properties&lt;br /&gt;
// copyright 2000 Eric Gunnerson&lt;br /&gt;
class Color&lt;br /&gt;
{&lt;br /&gt;
    public Color(int red, int green, int blue)&lt;br /&gt;
    {&lt;br /&gt;
        this.red = red;&lt;br /&gt;
        this.green = green;&lt;br /&gt;
        this.blue = blue;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    int    red;&lt;br /&gt;
    int    green;&lt;br /&gt;
    int    blue;&lt;br /&gt;
    &lt;br /&gt;
    public static Color Red&lt;br /&gt;
    {&lt;br /&gt;
        get&lt;br /&gt;
        {&lt;br /&gt;
            return(new Color(255, 0, 0));&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    public static Color Green&lt;br /&gt;
    {&lt;br /&gt;
        get&lt;br /&gt;
        {&lt;br /&gt;
            return(new Color(0, 255, 0));&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    public static Color Blue&lt;br /&gt;
    {&lt;br /&gt;
        get&lt;br /&gt;
        {&lt;br /&gt;
            return(new Color(0, 0, 255));&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class StaticProperties&lt;br /&gt;
{&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        Color background = Color.Red;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Properties: Use of Properties==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
A Programmer&amp;quot;s Introduction to C# (Second Edition)&lt;br /&gt;
by Eric Gunnerson&lt;br /&gt;
Publisher: Apress  L.P.&lt;br /&gt;
ISBN: 1-893115-62-3&lt;br /&gt;
*/&lt;br /&gt;
// 18 - Properties\Use of Properties&lt;br /&gt;
// copyright 2000 Eric Gunnerson&lt;br /&gt;
using System;&lt;br /&gt;
public class Auto&lt;br /&gt;
{&lt;br /&gt;
    public Auto(int id, string name)&lt;br /&gt;
    {&lt;br /&gt;
        this.id = id;&lt;br /&gt;
        this.name = name;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    // query to find # produced&lt;br /&gt;
    public int ProductionCount&lt;br /&gt;
    {&lt;br /&gt;
        get&lt;br /&gt;
        {&lt;br /&gt;
            if (productionCount == -1)&lt;br /&gt;
            {&lt;br /&gt;
                // fetch count from database here.&lt;br /&gt;
            }&lt;br /&gt;
            return(productionCount);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    public int SalesCount&lt;br /&gt;
    {&lt;br /&gt;
        get&lt;br /&gt;
        {&lt;br /&gt;
            if (salesCount == -1)&lt;br /&gt;
            {&lt;br /&gt;
                // query each dealership for data&lt;br /&gt;
            }&lt;br /&gt;
            return(salesCount);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    string name;&lt;br /&gt;
    int id;&lt;br /&gt;
    int productionCount = -1;&lt;br /&gt;
    int salesCount = -1;&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Properties:Virtual Properties==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
A Programmer&amp;quot;s Introduction to C# (Second Edition)&lt;br /&gt;
by Eric Gunnerson&lt;br /&gt;
Publisher: Apress  L.P.&lt;br /&gt;
ISBN: 1-893115-62-3&lt;br /&gt;
*/&lt;br /&gt;
// 18 - Properties\Virtual Properties&lt;br /&gt;
// copyright 2000 Eric Gunnerson&lt;br /&gt;
using System;&lt;br /&gt;
public abstract class DrawingObject&lt;br /&gt;
{&lt;br /&gt;
    public abstract string Name&lt;br /&gt;
    {&lt;br /&gt;
        get;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
class Circle: DrawingObject&lt;br /&gt;
{&lt;br /&gt;
    string name = &amp;quot;Circle&amp;quot;;&lt;br /&gt;
    &lt;br /&gt;
    public override string Name&lt;br /&gt;
    {&lt;br /&gt;
        get&lt;br /&gt;
        {&lt;br /&gt;
            return(name);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class PropertiesVirtualProperties&lt;br /&gt;
{&lt;br /&gt;
    public static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        DrawingObject d = new Circle();&lt;br /&gt;
        Console.WriteLine(&amp;quot;Name: {0}&amp;quot;, d.Name);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The use of an abstract property==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
C# Programming Tips &amp;amp; Techniques&lt;br /&gt;
by Charles Wright, Kris Jamsa&lt;br /&gt;
Publisher: Osborne/McGraw-Hill (December 28, 2001)&lt;br /&gt;
ISBN: 0072193794&lt;br /&gt;
*/&lt;br /&gt;
//&lt;br /&gt;
// Abstract.cs -- Demonsrates the use of an abstract property.&lt;br /&gt;
//&lt;br /&gt;
//                Compile this program with the following command line:&lt;br /&gt;
//                    C:&amp;gt;csc Abstract.cs&lt;br /&gt;
//&lt;br /&gt;
namespace nsAbstract&lt;br /&gt;
{&lt;br /&gt;
    using System;&lt;br /&gt;
    using System.Runtime.InteropServices;&lt;br /&gt;
    public class AbstractPro&lt;br /&gt;
    {&lt;br /&gt;
        static public void Main ()&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine (clsAbstract.StaticMethod());&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    //&lt;br /&gt;
    // To use the abstract modifier on a method, the class also must&lt;br /&gt;
    // be declared as abastract&lt;br /&gt;
    abstract class clsAbstract&lt;br /&gt;
    {&lt;br /&gt;
    //&lt;br /&gt;
    // To declare an abstract method, end the declaration with a semicolon.&lt;br /&gt;
    // Do not provide a body for the method.&lt;br /&gt;
        abstract public int AbstractMethod();&lt;br /&gt;
    //&lt;br /&gt;
    // An abstract class may contain a static method. You do not have&lt;br /&gt;
    // to declare an instance of the class to access a static method&lt;br /&gt;
        static public double StaticMethod()&lt;br /&gt;
        {&lt;br /&gt;
            return (3.14159 * 3.14159);&lt;br /&gt;
        }&lt;br /&gt;
        abstract public long Prop&lt;br /&gt;
        {&lt;br /&gt;
            get;&lt;br /&gt;
            set;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    //&lt;br /&gt;
    // Inherit from the abstract class. The following class implements&lt;br /&gt;
    // the AbstractMethod().&lt;br /&gt;
    // The access level of the derived class method must be the same&lt;br /&gt;
    // as the access level of the base class abstract method.&lt;br /&gt;
    class clsDerivedFromAbstract : clsAbstract&lt;br /&gt;
    {&lt;br /&gt;
        override public int AbstractMethod()&lt;br /&gt;
        {&lt;br /&gt;
            return (0);&lt;br /&gt;
        }&lt;br /&gt;
        override public long Prop&lt;br /&gt;
        {&lt;br /&gt;
            get&lt;br /&gt;
            {&lt;br /&gt;
                return (val);&lt;br /&gt;
            }&lt;br /&gt;
            set&lt;br /&gt;
            {&lt;br /&gt;
                val = value;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        private long val;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Use properties to set and get private members==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
C#: The Complete Reference &lt;br /&gt;
by Herbert Schildt &lt;br /&gt;
Publisher: Osborne/McGraw-Hill (March 8, 2002)&lt;br /&gt;
ISBN: 0072134852&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
// Use properties to set and get private members. &lt;br /&gt;
 &lt;br /&gt;
using System; &lt;br /&gt;
 &lt;br /&gt;
// A class for two-dimensional objects. &lt;br /&gt;
class TwoDShape { &lt;br /&gt;
  double pri_width;  // now private &lt;br /&gt;
  double pri_height; // now private  &lt;br /&gt;
 &lt;br /&gt;
  // Properties for width and height. &lt;br /&gt;
  public double width { &lt;br /&gt;
     get { return pri_width; } &lt;br /&gt;
     set { pri_width = value; } &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  public double height { &lt;br /&gt;
     get { return pri_height; } &lt;br /&gt;
     set { pri_height = value; } &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  public void showDim() { &lt;br /&gt;
    Console.WriteLine(&amp;quot;Width and height are &amp;quot; + &lt;br /&gt;
                       width + &amp;quot; and &amp;quot; + height); &lt;br /&gt;
  } &lt;br /&gt;
} &lt;br /&gt;
 &lt;br /&gt;
// A derived class of TwoDShape for triangles. &lt;br /&gt;
class Triangle : TwoDShape { &lt;br /&gt;
  public string style; // style of triangle &lt;br /&gt;
   &lt;br /&gt;
  // Return area of triangle. &lt;br /&gt;
  public double area() { &lt;br /&gt;
    return width * height / 2;  &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  // Display a triangle&amp;quot;s style. &lt;br /&gt;
  public void showStyle() { &lt;br /&gt;
    Console.WriteLine(&amp;quot;Triangle is &amp;quot; + style); &lt;br /&gt;
  } &lt;br /&gt;
} &lt;br /&gt;
 &lt;br /&gt;
public class Shapes2 { &lt;br /&gt;
  public static void Main() { &lt;br /&gt;
    Triangle t1 = new Triangle(); &lt;br /&gt;
    Triangle t2 = new Triangle(); &lt;br /&gt;
 &lt;br /&gt;
    t1.width = 4.0; &lt;br /&gt;
    t1.height = 4.0; &lt;br /&gt;
    t1.style = &amp;quot;isosceles&amp;quot;; &lt;br /&gt;
 &lt;br /&gt;
    t2.width = 8.0; &lt;br /&gt;
    t2.height = 12.0; &lt;br /&gt;
    t2.style = &amp;quot;right&amp;quot;; &lt;br /&gt;
 &lt;br /&gt;
    Console.WriteLine(&amp;quot;Info for t1: &amp;quot;); &lt;br /&gt;
    t1.showStyle(); &lt;br /&gt;
    t1.showDim(); &lt;br /&gt;
    Console.WriteLine(&amp;quot;Area is &amp;quot; + t1.area()); &lt;br /&gt;
 &lt;br /&gt;
    Console.WriteLine(); &lt;br /&gt;
 &lt;br /&gt;
    Console.WriteLine(&amp;quot;Info for t2: &amp;quot;); &lt;br /&gt;
    t2.showStyle(); &lt;br /&gt;
    t2.showDim(); &lt;br /&gt;
    Console.WriteLine(&amp;quot;Area is &amp;quot; + t2.area()); &lt;br /&gt;
  } &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>