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

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/struct/struct&amp;diff=5978&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/struct/struct&amp;diff=5978&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/struct/struct&amp;diff=5979&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/struct/struct&amp;diff=5979&amp;oldid=prev"/>
				<updated>2010-05-26T12:17:53Z</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 simple struct with method==&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;
struct Fraction {&lt;br /&gt;
  public int numerator;&lt;br /&gt;
  public int denominator;&lt;br /&gt;
  public void Print( ) {&lt;br /&gt;
    Console.WriteLine( &amp;quot;{0}/{1}&amp;quot;, numerator, denominator );&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public static void Main( ) {&lt;br /&gt;
    Fraction f;&lt;br /&gt;
    f.numerator   = 5;&lt;br /&gt;
    f.denominator = 10;&lt;br /&gt;
    f.Print( );&lt;br /&gt;
    Fraction f2 = f;&lt;br /&gt;
    f.Print( );&lt;br /&gt;
    f2.numerator = 1;&lt;br /&gt;
    f.Print( );&lt;br /&gt;
    f2.Print( );&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;5/10&lt;br /&gt;
5/10&lt;br /&gt;
5/10&lt;br /&gt;
1/10&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==class vs struct==&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;
using System.Collections.Generic;&lt;br /&gt;
using System.Text;&lt;br /&gt;
&lt;br /&gt;
class MyClass {&lt;br /&gt;
    public int val;&lt;br /&gt;
}&lt;br /&gt;
struct myStruct {&lt;br /&gt;
    public int val;&lt;br /&gt;
}&lt;br /&gt;
class Program {&lt;br /&gt;
    static void Main(string[] args) {&lt;br /&gt;
        MyClass objectA = new MyClass();&lt;br /&gt;
        MyClass objectB = objectA;&lt;br /&gt;
        objectA.val = 10;&lt;br /&gt;
        objectB.val = 20;&lt;br /&gt;
        myStruct structA = new myStruct();&lt;br /&gt;
        myStruct structB = structA;&lt;br /&gt;
        structA.val = 30;&lt;br /&gt;
        structB.val = 40;&lt;br /&gt;
        Console.WriteLine(&amp;quot;objectA.val = {0}&amp;quot;, objectA.val);&lt;br /&gt;
        Console.WriteLine(&amp;quot;objectB.val = {0}&amp;quot;, objectB.val);&lt;br /&gt;
        Console.WriteLine(&amp;quot;structA.val = {0}&amp;quot;, structA.val);&lt;br /&gt;
        Console.WriteLine(&amp;quot;structB.val = {0}&amp;quot;, structB.val);&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Declare a simple struct==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;struct Fraction {&lt;br /&gt;
  public int numerator;&lt;br /&gt;
  public int denominator;&lt;br /&gt;
}&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public static void Main( ) {&lt;br /&gt;
    Fraction f;&lt;br /&gt;
    f.numerator   = 5;&lt;br /&gt;
    f.denominator = 10;&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Difference between class and struct during the reference passing==&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;
using System.Collections.Generic;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Text;&lt;br /&gt;
&lt;br /&gt;
    class MyClass&lt;br /&gt;
    {&lt;br /&gt;
        public int val;&lt;br /&gt;
    }&lt;br /&gt;
    struct myStruct&lt;br /&gt;
    {&lt;br /&gt;
        public int val;&lt;br /&gt;
    }&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            MyClass objectA = new MyClass();&lt;br /&gt;
            MyClass objectB = objectA;&lt;br /&gt;
            objectA.val = 10;&lt;br /&gt;
            objectB.val = 20;&lt;br /&gt;
            myStruct structA = new myStruct();&lt;br /&gt;
            myStruct structB = structA;&lt;br /&gt;
            structA.val = 30;&lt;br /&gt;
            structB.val = 40;&lt;br /&gt;
            Console.WriteLine(&amp;quot;objectA.val = {0}&amp;quot;, objectA.val);&lt;br /&gt;
            Console.WriteLine(&amp;quot;objectB.val = {0}&amp;quot;, objectB.val);&lt;br /&gt;
            Console.WriteLine(&amp;quot;structA.val = {0}&amp;quot;, structA.val);&lt;br /&gt;
            Console.WriteLine(&amp;quot;structB.val = {0}&amp;quot;, structB.val);&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reference value type in a struct==&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;
struct Point&lt;br /&gt;
{&lt;br /&gt;
   public int X;&lt;br /&gt;
   public int Y;&lt;br /&gt;
}&lt;br /&gt;
class MainClass&lt;br /&gt;
{&lt;br /&gt;
   static void Main()&lt;br /&gt;
   {&lt;br /&gt;
      Point p1, p2, p3;&lt;br /&gt;
      p1.X = 10; p1.Y = 10;&lt;br /&gt;
      p2.X = 20; p2.Y = 20;&lt;br /&gt;
      p3.X = p1.X + p2.X;&lt;br /&gt;
      p3.Y = p1.Y + p2.Y;&lt;br /&gt;
      Console.WriteLine(&amp;quot;p1:  {0}, {1}&amp;quot;, p1.X, p1.Y);&lt;br /&gt;
      Console.WriteLine(&amp;quot;p2: {0}, {1}&amp;quot;, p2.X, p2.Y);&lt;br /&gt;
      Console.WriteLine(&amp;quot;p3:  {0}, {1}&amp;quot;, p3.X, p3.Y);&lt;br /&gt;
   }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;p1:  10, 10&lt;br /&gt;
p2: 20, 20&lt;br /&gt;
p3:  30, 30&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Structures==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;A struct is similar to a class, but is a value type, not a reference type.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Here is the general form of a struct:&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;struct name : interfaces {&lt;br /&gt;
        // member declarations&lt;br /&gt;
    }&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;OL&amp;gt;&amp;lt;LI&amp;gt;Structures cannot inherit other structures or classes&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;Structures cannot be used as a base for other structures or classes.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;A structure can implement one or more interfaces.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;Structure members can be methods, fields, indexers, properties, operator methods, and events.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;Structures can also define constructors, but not destructors.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;You cannot define a default (parameterless) constructor for a structure.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;A default constructor is automatically defined for all structures, and this default constructor can&amp;quot;t be changed.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;Structure members cannot be specified as abstract, virtual, or protected.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;When new is used, the specified constructor is called.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;When new is not used, the object is still created, but it is not initialized.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;When you assign one structure to another, a copy of the structure object is made.&amp;lt;/LI&amp;gt;&amp;lt;/OL&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==struct with value types==&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;
struct PointerStruct&lt;br /&gt;
{&lt;br /&gt;
  public int x, y;&lt;br /&gt;
}&lt;br /&gt;
class MainClass&lt;br /&gt;
{&lt;br /&gt;
  public static void Main(string[] args)&lt;br /&gt;
  {&lt;br /&gt;
    PointerStruct f1 = new PointerStruct();&lt;br /&gt;
    f1.x = 100;&lt;br /&gt;
    f1.y = 100;&lt;br /&gt;
    PointerStruct f2 = f1;&lt;br /&gt;
    Console.WriteLine(&amp;quot;F1.x = {0}&amp;quot;, f1.x);&lt;br /&gt;
    Console.WriteLine(&amp;quot;F1.y = {0}&amp;quot;, f1.y);&lt;br /&gt;
    Console.WriteLine(&amp;quot;F2.x = {0}&amp;quot;, f2.x);&lt;br /&gt;
    Console.WriteLine(&amp;quot;F2.y = {0}&amp;quot;, f2.y);&lt;br /&gt;
    Console.WriteLine(&amp;quot;-&amp;gt; Changing f2.x&amp;quot;);&lt;br /&gt;
    f2.x = 900;&lt;br /&gt;
    Console.WriteLine(&amp;quot;F2.x = {0}&amp;quot;, f2.x);&lt;br /&gt;
    Console.WriteLine(&amp;quot;F1.x = {0}\n&amp;quot;, f1.x);&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;F1.x = 100&lt;br /&gt;
F1.y = 100&lt;br /&gt;
F2.x = 100&lt;br /&gt;
F2.y = 100&lt;br /&gt;
-&amp;gt; Changing f2.x&lt;br /&gt;
F2.x = 900&lt;br /&gt;
F1.x = 100&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==struct with value types and ref types==&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 MyClass&lt;br /&gt;
{&lt;br /&gt;
  public string x;&lt;br /&gt;
  public MyClass(string s)  {&lt;br /&gt;
      x = s;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
struct MyStruct&lt;br /&gt;
{&lt;br /&gt;
  public MyClass refType;   // Ref type.&lt;br /&gt;
  public int valueType;     // Val type&lt;br /&gt;
  public MyStruct(string s)&lt;br /&gt;
  {&lt;br /&gt;
    refType = new MyClass(s);&lt;br /&gt;
    valueType = 9;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
class MainClass&lt;br /&gt;
{&lt;br /&gt;
  public static void Main(string[] args)&lt;br /&gt;
  {&lt;br /&gt;
    MyStruct valWithRef = new MyStruct(&amp;quot;Initial value&amp;quot;);&lt;br /&gt;
    valWithRef.valueType = 6;&lt;br /&gt;
    MyStruct valWithRef2;&lt;br /&gt;
    valWithRef2 = valWithRef;&lt;br /&gt;
    valWithRef2.refType.x = &amp;quot;I am NEW!&amp;quot;;&lt;br /&gt;
    valWithRef2.valueType = 7;&lt;br /&gt;
    Console.WriteLine(&amp;quot;Values after change:&amp;quot;);&lt;br /&gt;
    Console.WriteLine(&amp;quot;valWithRef.refType.x is {0}&amp;quot;, valWithRef.refType.x);&lt;br /&gt;
    Console.WriteLine(&amp;quot;valWithRef2.refType.x is {0}&amp;quot;, valWithRef2.refType.x);&lt;br /&gt;
    Console.WriteLine(&amp;quot;valWithRef.valueType is {0}&amp;quot;, valWithRef.valueType);&lt;br /&gt;
    Console.WriteLine(&amp;quot;valWithRef2.valueType is {0}&amp;quot;, valWithRef2.valueType);&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Values after change:&lt;br /&gt;
valWithRef.refType.x is I am NEW!&lt;br /&gt;
valWithRef2.refType.x is I am NEW!&lt;br /&gt;
valWithRef.valueType is 6&lt;br /&gt;
valWithRef2.valueType is 7&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>