<?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%2FCSharp_Tutorial%2FClass%2FMember_Variable</id>
		<title>Csharp/CSharp Tutorial/Class/Member Variable - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FCSharp_Tutorial%2FClass%2FMember_Variable"/>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Class/Member_Variable&amp;action=history"/>
		<updated>2026-04-29T17:14:59Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Class/Member_Variable&amp;diff=5609&amp;oldid=prev</id>
		<title> в 15:31, 26 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Class/Member_Variable&amp;diff=5609&amp;oldid=prev"/>
				<updated>2010-05-26T15:31:53Z</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/CSharp_Tutorial/Class/Member_Variable&amp;diff=5610&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Class/Member_Variable&amp;diff=5610&amp;oldid=prev"/>
				<updated>2010-05-26T12:16:01Z</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;==A class with method and member variables==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
class Employee&lt;br /&gt;
{&lt;br /&gt;
    // constructor&lt;br /&gt;
    public Employee(string name, float billingRate)&lt;br /&gt;
    {&lt;br /&gt;
        this.name = name;&lt;br /&gt;
        this.billingRate = billingRate;&lt;br /&gt;
    }&lt;br /&gt;
    // figure out the charge based on Employee&amp;quot;s rate&lt;br /&gt;
    public float CalculateCharge(float hours)&lt;br /&gt;
    {&lt;br /&gt;
        return(hours * billingRate);&lt;br /&gt;
    }&lt;br /&gt;
    // return the name of this type&lt;br /&gt;
    public string TypeName()&lt;br /&gt;
    {&lt;br /&gt;
        return(&amp;quot;Employee&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    private string name;&lt;br /&gt;
    protected float billingRate;&lt;br /&gt;
}&lt;br /&gt;
class MainClass&lt;br /&gt;
{&lt;br /&gt;
    public static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        Employee Employee = new Employee(&amp;quot;A&amp;quot;, 21.20F);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Name is: {0}&amp;quot;, Employee.TypeName());&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Name is: Employee&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Add a method to access the field variables==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;  &lt;br /&gt;
  &lt;br /&gt;
class Building {   &lt;br /&gt;
  public int area;     &lt;br /&gt;
  public int occupants;&lt;br /&gt;
 &lt;br /&gt;
  &lt;br /&gt;
  public void areaPerPerson() {  &lt;br /&gt;
    Console.WriteLine(&amp;quot;Display the area per person.&amp;quot;);&lt;br /&gt;
    Console.WriteLine(&amp;quot;  &amp;quot; + area / occupants + &lt;br /&gt;
                      &amp;quot; area per person&amp;quot;); &lt;br /&gt;
  }  &lt;br /&gt;
}   &lt;br /&gt;
 &lt;br /&gt;
class BuildingDemo {   &lt;br /&gt;
  public static void Main() {   &lt;br /&gt;
    Building house = new Building();   &lt;br /&gt;
    Building office = new Building(); &lt;br /&gt;
 &lt;br /&gt;
    house.occupants = 4;  &lt;br /&gt;
    house.area = 2500;  &lt;br /&gt;
 &lt;br /&gt;
    // assign values to fields in office &lt;br /&gt;
    office.occupants = 25;  &lt;br /&gt;
    office.area = 4200;  &lt;br /&gt;
   &lt;br /&gt;
    Console.WriteLine(&amp;quot;house has:\n  &amp;quot; + &lt;br /&gt;
                      house.occupants + &amp;quot; occupants\n  &amp;quot; + &lt;br /&gt;
                      house.area + &amp;quot; total area&amp;quot;); &lt;br /&gt;
    house.areaPerPerson(); &lt;br /&gt;
 &lt;br /&gt;
    Console.WriteLine(); &lt;br /&gt;
 &lt;br /&gt;
    Console.WriteLine(&amp;quot;office has:\n  &amp;quot; + &lt;br /&gt;
                      office.occupants + &amp;quot; occupants\n  &amp;quot; + &lt;br /&gt;
                      office.area + &amp;quot; total area&amp;quot;); &lt;br /&gt;
    office.areaPerPerson(); &lt;br /&gt;
  }   &lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;house has:&lt;br /&gt;
  4 occupants&lt;br /&gt;
  2500 total area&lt;br /&gt;
Display the area per person.&lt;br /&gt;
  625 area per person&lt;br /&gt;
office has:&lt;br /&gt;
  25 occupants&lt;br /&gt;
  4200 total area&lt;br /&gt;
Display the area per person.&lt;br /&gt;
  168 area per person&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Call base constructor to init member variables==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;public class A&lt;br /&gt;
{&lt;br /&gt;
   public A( int x )&lt;br /&gt;
   {&lt;br /&gt;
      this.x = x;&lt;br /&gt;
   }&lt;br /&gt;
   public A() : this( 0 )&lt;br /&gt;
   {&lt;br /&gt;
   }&lt;br /&gt;
   internal int x;&lt;br /&gt;
}&lt;br /&gt;
public class B : A&lt;br /&gt;
{&lt;br /&gt;
   public B() : base( 1 )&lt;br /&gt;
   {&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
public class MainClass&lt;br /&gt;
{&lt;br /&gt;
   static void Main()&lt;br /&gt;
   {&lt;br /&gt;
      B b = new B();&lt;br /&gt;
      System.Console.WriteLine( &amp;quot;A.x = {0}&amp;quot;, b.x );&lt;br /&gt;
   }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;A.x = 1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==field initialization==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;class FieldInitExample&lt;br /&gt;
    {&lt;br /&gt;
        int x = 5;&lt;br /&gt;
        int y;&lt;br /&gt;
        public FieldInitExample() : this(5)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
        public FieldInitExample(int y)&lt;br /&gt;
        {&lt;br /&gt;
            this.y = y;&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==fields==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;class FieldExample&lt;br /&gt;
{&lt;br /&gt;
    private static int idCounter;&lt;br /&gt;
    protected int id;&lt;br /&gt;
    public string name;&lt;br /&gt;
    public int x;&lt;br /&gt;
    public int y;&lt;br /&gt;
    private System.DateTime createDate;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==How to use a &amp;quot;has a&amp;quot; relationship==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;public class Engine&lt;br /&gt;
{&lt;br /&gt;
  public int cylinders;&lt;br /&gt;
  public int horsepower;&lt;br /&gt;
  public void Start()&lt;br /&gt;
  {&lt;br /&gt;
    System.Console.WriteLine(&amp;quot;Engine started&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
public class Car&lt;br /&gt;
{&lt;br /&gt;
  public string make;&lt;br /&gt;
  public Engine engine;  // Car has an Engine&lt;br /&gt;
  public void Start()&lt;br /&gt;
  {&lt;br /&gt;
    engine.Start();&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
class MainClass&lt;br /&gt;
{&lt;br /&gt;
  public static void Main()&lt;br /&gt;
  {&lt;br /&gt;
    System.Console.WriteLine(&amp;quot;Creating a Car object&amp;quot;);&lt;br /&gt;
    Car myCar = new Car();&lt;br /&gt;
    myCar.make = &amp;quot;Toyota&amp;quot;;&lt;br /&gt;
    System.Console.WriteLine(&amp;quot;Creating an Engine object&amp;quot;);&lt;br /&gt;
    myCar.engine = new Engine();&lt;br /&gt;
    myCar.engine.cylinders = 4;&lt;br /&gt;
    myCar.engine.horsepower = 180;&lt;br /&gt;
    System.Console.WriteLine(&amp;quot;myCar.make = &amp;quot; + myCar.make);&lt;br /&gt;
    System.Console.WriteLine(&amp;quot;myCar.engine.cylinders = &amp;quot; + myCar.engine.cylinders);&lt;br /&gt;
    System.Console.WriteLine(&amp;quot;myCar.engine.horsepower = &amp;quot; + myCar.engine.horsepower);&lt;br /&gt;
    myCar.Start();&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Creating a Car object&lt;br /&gt;
Creating an Engine object&lt;br /&gt;
myCar.make = Toyota&lt;br /&gt;
myCar.engine.cylinders = 4&lt;br /&gt;
myCar.engine.horsepower = 180&lt;br /&gt;
Engine started&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Illustrates how to assign default values to fields using initializers==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;class PC&lt;br /&gt;
{&lt;br /&gt;
  public string make = &amp;quot;AAA&amp;quot;;&lt;br /&gt;
  public string model = &amp;quot;T&amp;quot;;&lt;br /&gt;
  public string color;&lt;br /&gt;
  public int yearBuilt = 1910;&lt;br /&gt;
  public void Start()&lt;br /&gt;
  {&lt;br /&gt;
    System.Console.WriteLine(yearBuilt + &amp;quot; yearBuilt&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
class MainClass&lt;br /&gt;
{&lt;br /&gt;
  public static void Main()&lt;br /&gt;
  {&lt;br /&gt;
    PC myPC = new PC();&lt;br /&gt;
    System.Console.WriteLine(&amp;quot;myPC.make = &amp;quot; + myPC.make);&lt;br /&gt;
    System.Console.WriteLine(&amp;quot;myPC.model = &amp;quot; + myPC.model);&lt;br /&gt;
    if (myPC.color == null)&lt;br /&gt;
    {&lt;br /&gt;
      System.Console.WriteLine(&amp;quot;myPC.color is null&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    System.Console.WriteLine(&amp;quot;myPC.yearBuilt = &amp;quot; + myPC.yearBuilt);&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;myPC.make = AAA&lt;br /&gt;
myPC.model = T&lt;br /&gt;
myPC.color is null&lt;br /&gt;
myPC.yearBuilt = 1910&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Use this and base together to init a class==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
class Base&lt;br /&gt;
{&lt;br /&gt;
   public Base( int x )&lt;br /&gt;
   {&lt;br /&gt;
      Console.WriteLine( &amp;quot;Base.Base(int)&amp;quot; );&lt;br /&gt;
      this.x = x;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   public int x = 0;&lt;br /&gt;
}&lt;br /&gt;
class Derived : Base&lt;br /&gt;
{&lt;br /&gt;
   public Derived( int a ):base( a )&lt;br /&gt;
   {&lt;br /&gt;
      Console.WriteLine( &amp;quot;Derived.Derived(int)&amp;quot; );&lt;br /&gt;
      this.a = a;&lt;br /&gt;
   }&lt;br /&gt;
   public Derived( int a, int b ):this( a )&lt;br /&gt;
   {&lt;br /&gt;
      Console.WriteLine( &amp;quot;Derived.Derived(int, int)&amp;quot; );&lt;br /&gt;
      this.a = a;&lt;br /&gt;
      this.b = b;&lt;br /&gt;
   }&lt;br /&gt;
   public int a = 0;&lt;br /&gt;
   public int b = 0;&lt;br /&gt;
}&lt;br /&gt;
public class MainClass&lt;br /&gt;
{&lt;br /&gt;
   static void Main()&lt;br /&gt;
   {&lt;br /&gt;
      Derived b = new Derived( 1, 2 );&lt;br /&gt;
   }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Base.Base(int)&lt;br /&gt;
Derived.Derived(int)&lt;br /&gt;
Derived.Derived(int, int)&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>