<?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%2FBase_Class</id>
		<title>Csharp/CSharp Tutorial/Class/Base Class - История изменений</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%2FBase_Class"/>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Class/Base_Class&amp;action=history"/>
		<updated>2026-04-29T19:24:46Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Class/Base_Class&amp;diff=5623&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/Base_Class&amp;diff=5623&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/Base_Class&amp;diff=5624&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/Base_Class&amp;diff=5624&amp;oldid=prev"/>
				<updated>2010-05-26T12:16:03Z</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;==Add constructors to base 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;
 &lt;br /&gt;
class Shape { &lt;br /&gt;
  double pri_width;  // private &lt;br /&gt;
  double pri_height; // private  &lt;br /&gt;
 &lt;br /&gt;
  public Shape(double w, double h) { &lt;br /&gt;
    width = w; &lt;br /&gt;
    height = h; &lt;br /&gt;
  } &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;
class Triangle : Shape { &lt;br /&gt;
  string style; // private &lt;br /&gt;
   &lt;br /&gt;
  public Triangle(string s, double w, double h) : base(w, h) { &lt;br /&gt;
    style = s;  &lt;br /&gt;
  } &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;
class MainClass { &lt;br /&gt;
  public static void Main() { &lt;br /&gt;
    Triangle t1 = new Triangle(&amp;quot;isosceles&amp;quot;, 4.0, 4.0); &lt;br /&gt;
    Triangle t2 = new Triangle(&amp;quot;right&amp;quot;, 8.0, 12.0); &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;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Info for t1:&lt;br /&gt;
Triangle is isosceles&lt;br /&gt;
Width and height are 4 and 4&lt;br /&gt;
Area is 8&lt;br /&gt;
Info for t2:&lt;br /&gt;
Triangle is right&lt;br /&gt;
Width and height are 8 and 12&lt;br /&gt;
Area is 48&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Add more constructors to base 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;
 &lt;br /&gt;
class Shape { &lt;br /&gt;
  double pri_width;  // private &lt;br /&gt;
  double pri_height; // private  &lt;br /&gt;
 &lt;br /&gt;
  public Shape() { &lt;br /&gt;
    width = height = 0.0; &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  // Constructor for Shape. &lt;br /&gt;
  public Shape(double w, double h) { &lt;br /&gt;
    width = w; &lt;br /&gt;
    height = h; &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  // Construct object with equal width and height. &lt;br /&gt;
  public Shape(double x) { &lt;br /&gt;
    width = height = x; &lt;br /&gt;
  } &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 Shape for triangles. &lt;br /&gt;
class Triangle : Shape { &lt;br /&gt;
  string style; // private &lt;br /&gt;
   &lt;br /&gt;
  /* A default constructor. This automatically invokes &lt;br /&gt;
     the default constructor of Shape. */ &lt;br /&gt;
  public Triangle() { &lt;br /&gt;
    style = &amp;quot;null&amp;quot;; &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  // Constructor that takes three arguments. &lt;br /&gt;
  public Triangle(string s, double w, double h) : base(w, h) { &lt;br /&gt;
    style = s;  &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  // Construct an isosceles triangle. &lt;br /&gt;
  public Triangle(double x) : base(x) { &lt;br /&gt;
    style = &amp;quot;isosceles&amp;quot;;  &lt;br /&gt;
  } &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;
class MainClass { &lt;br /&gt;
  public static void Main() { &lt;br /&gt;
    Triangle t1 = new Triangle(); &lt;br /&gt;
    Triangle t2 = new Triangle(&amp;quot;right&amp;quot;, 8.0, 12.0); &lt;br /&gt;
    Triangle t3 = new Triangle(4.0); &lt;br /&gt;
 &lt;br /&gt;
    t1 = t2; &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;
    Console.WriteLine(); &lt;br /&gt;
 &lt;br /&gt;
    Console.WriteLine(&amp;quot;Info for t3: &amp;quot;); &lt;br /&gt;
    t3.showStyle(); &lt;br /&gt;
    t3.showDim(); &lt;br /&gt;
    Console.WriteLine(&amp;quot;Area is &amp;quot; + t3.area()); &lt;br /&gt;
 &lt;br /&gt;
    Console.WriteLine(); &lt;br /&gt;
  } &lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Info for t1:&lt;br /&gt;
Triangle is right&lt;br /&gt;
Width and height are 8 and 12&lt;br /&gt;
Area is 48&lt;br /&gt;
Info for t2:&lt;br /&gt;
Triangle is right&lt;br /&gt;
Width and height are 8 and 12&lt;br /&gt;
Area is 48&lt;br /&gt;
Info for t3:&lt;br /&gt;
Triangle is isosceles&lt;br /&gt;
Width and height are 4 and 4&lt;br /&gt;
Area is 8&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Call constructor in base 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;
public class BaseClass&lt;br /&gt;
{&lt;br /&gt;
    public BaseClass(int x)&lt;br /&gt;
    {&lt;br /&gt;
        this.x = x;&lt;br /&gt;
    }&lt;br /&gt;
    public int X&lt;br /&gt;
    {&lt;br /&gt;
        get&lt;br /&gt;
        {&lt;br /&gt;
            return(x);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    int    x;&lt;br /&gt;
}&lt;br /&gt;
public class Derived: BaseClass&lt;br /&gt;
{&lt;br /&gt;
    public Derived(int x): base(x)&lt;br /&gt;
    {&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;
        Derived d = new Derived(15);&lt;br /&gt;
        Console.WriteLine(&amp;quot;X = {0}&amp;quot;, d.X);&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;X = 15&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Define base class another cs file==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;//File: base.cs&lt;br /&gt;
using System;&lt;br /&gt;
&lt;br /&gt;
namespace BaseClassNS&lt;br /&gt;
{&lt;br /&gt;
   public class MyBaseClass&lt;br /&gt;
   {&lt;br /&gt;
      public void PrintMe()&lt;br /&gt;
      {&lt;br /&gt;
         Console.WriteLine(&amp;quot;I am MyBaseClass&amp;quot;);&lt;br /&gt;
      }&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
//////////////////////////////////////&lt;br /&gt;
//MainClass.cs&lt;br /&gt;
using System;&lt;br /&gt;
using BaseClassNS;&lt;br /&gt;
namespace UsesBaseClass&lt;br /&gt;
{&lt;br /&gt;
   class DerivedClass : MyBaseClass&lt;br /&gt;
   {&lt;br /&gt;
   }&lt;br /&gt;
   class MainClass&lt;br /&gt;
   {&lt;br /&gt;
      static void Main()&lt;br /&gt;
      {&lt;br /&gt;
         DerivedClass mdc = new DerivedClass();&lt;br /&gt;
         mdc.PrintMe();&lt;br /&gt;
      }&lt;br /&gt;
   }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pass a derived class reference to a base class reference.==&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 Shape { &lt;br /&gt;
  double pri_width;  // private &lt;br /&gt;
  double pri_height; // private &lt;br /&gt;
 &lt;br /&gt;
  public Shape() { &lt;br /&gt;
    width = height = 0.0; &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  public Shape(double w, double h) { &lt;br /&gt;
    width = w; &lt;br /&gt;
    height = h; &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  public Shape(double x) { &lt;br /&gt;
    width = height = x; &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  public Shape(Shape ob) { &lt;br /&gt;
    width = ob.width; &lt;br /&gt;
    height = ob.height; &lt;br /&gt;
  } &lt;br /&gt;
 &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;
class Triangle : Shape { &lt;br /&gt;
  string style; // private &lt;br /&gt;
   &lt;br /&gt;
  // A default constructor. &lt;br /&gt;
  public Triangle() { &lt;br /&gt;
    style = &amp;quot;null&amp;quot;; &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  // Constructor for Triangle. &lt;br /&gt;
  public Triangle(string s, double w, double h) : base(w, h) { &lt;br /&gt;
    style = s;  &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  // Construct an isosceles triangle. &lt;br /&gt;
  public Triangle(double x) : base(x) { &lt;br /&gt;
    style = &amp;quot;isosceles&amp;quot;;  &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  // Construct an object from an object. &lt;br /&gt;
  public Triangle(Triangle ob) : base(ob) { &lt;br /&gt;
    style = ob.style; &lt;br /&gt;
  } &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;
class MainClass { &lt;br /&gt;
  public static void Main() { &lt;br /&gt;
    Triangle t1 = new Triangle(&amp;quot;right&amp;quot;, 8.0, 12.0); &lt;br /&gt;
 &lt;br /&gt;
    // make a copy of t1 &lt;br /&gt;
    Triangle t2 = new Triangle(t1); &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;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Info for t1:&lt;br /&gt;
Triangle is right&lt;br /&gt;
Width and height are 8 and 12&lt;br /&gt;
Area is 48&lt;br /&gt;
Info for t2:&lt;br /&gt;
Triangle is right&lt;br /&gt;
Width and height are 8 and 12&lt;br /&gt;
Area is 48&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>