{"id":24590,"date":"2015-07-15T01:10:54","date_gmt":"2015-07-14T22:10:54","guid":{"rendered":"http:\/\/studentpmr.ru\/?p=24590"},"modified":"2015-07-15T01:10:54","modified_gmt":"2015-07-14T22:10:54","slug":"%d0%bf%d1%80%d0%be%d0%b3%d1%80%d0%b0%d0%bc%d0%bc%d0%b0-%d1%81-%d0%b8%d1%81%d0%bf%d0%be%d0%bb%d1%8c%d0%b7%d0%be%d0%b2%d0%b0%d0%bd%d0%b8%d0%b5%d0%bc-%d0%ba%d0%bb%d0%b0%d1%81%d1%81%d0%be%d0%b2-%d0%bb","status":"publish","type":"post","link":"http:\/\/studentpmr.ru\/?p=24590","title":{"rendered":"\u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u0432. \u041b\u0430\u0431\u043e\u0440\u0430\u0442\u043e\u0440\u043d\u0430\u044f \u043f\u043e \u041e\u041e\u041f."},"content":{"rendered":"<ol>\n<li>using System;<\/li>\n<\/ol>\n<p>namespace primer__klassa_1<\/p>\n<p>{<\/p>\n<p>\/\/\/ &lt;summary&gt;<\/p>\n<p>\/\/\/ Summary description for Class1.<\/p>\n<p>\/\/\/ &lt;\/summary&gt;<!--more--><\/p>\n<p>class MyClass<\/p>\n<p>{<\/p>\n<p>public MyClass()<\/p>\n<p>{<\/p>\n<p>Console.WriteLine(&#187; constructor_1&#8243;);<\/p>\n<p>}<\/p>\n<p>public MyClass(int value)<\/p>\n<p>{<\/p>\n<p>MyField = value;<\/p>\n<p>Console.WriteLine(&#187; constructor_2&#8243;);<\/p>\n<p>}<\/p>\n<p>~MyClass()<\/p>\n<p>{<\/p>\n<p>Console.WriteLine(&#171;Destructor&#187;);<\/p>\n<p>}<\/p>\n<p>public const int MyConst = 12;<\/p>\n<p>public int MyField = 34;<\/p>\n<p>public void MyMethod()<\/p>\n<p>{<\/p>\n<p>Console.WriteLine(&#171;MyClass.MyMethod&#187;);<\/p>\n<p>}<\/p>\n<p>public int MyProperty<\/p>\n<p>{<\/p>\n<p>get<\/p>\n<p>{<\/p>\n<p>return MyField;<\/p>\n<p>}<\/p>\n<p>set<\/p>\n<p>{<\/p>\n<p>MyField = value;<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>public int this[int index]<\/p>\n<p>{<\/p>\n<p>get<\/p>\n<p>{<\/p>\n<p>return 0;<\/p>\n<p>}<\/p>\n<p>set<\/p>\n<p>{<\/p>\n<p>Console.WriteLine(&#171;this[{0}] = {1}&#187;, index, value);<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>public event EventHandler MyEvent;<\/p>\n<p>public static MyClass operator+(MyClass a, MyClass b)<\/p>\n<p>{<\/p>\n<p>return new MyClass(a.MyField + b.MyField);<\/p>\n<p>}<\/p>\n<p>internal class MyNestedClass<\/p>\n<p>{}<\/p>\n<p>}<\/p>\n<p>class Class1<\/p>\n<p>{<\/p>\n<p>[STAThread]<\/p>\n<p>static void Main(string[] args)<\/p>\n<p>{<\/p>\n<p>\/\/ Instance constructor usage<\/p>\n<p>MyClass a = new MyClass();<\/p>\n<p>MyClass b = new MyClass(123);<\/p>\n<p>\/\/ Constant usage<\/p>\n<p>Console.WriteLine(&#171;MyConst = {0}&#187;, MyClass.MyConst);<\/p>\n<p>\/\/ Field usage<\/p>\n<p>a.MyField++;<\/p>\n<p>Console.WriteLine(&#171;a.MyField = {0}&#187;, a.MyField);<\/p>\n<p>\/\/ Method usage<\/p>\n<p>a.MyMethod();<\/p>\n<p>\/\/ Property usage<\/p>\n<p>a.MyProperty++;<\/p>\n<p>Console.WriteLine(&#171;a.MyProperty = {0}&#187;, a.MyProperty);<\/p>\n<p>\/\/ Indexer usage<\/p>\n<p>a[3] = a[1] = a[2];<\/p>\n<p>Console.WriteLine(&#171;a[3] = {0}&#187;, a[3]);<\/p>\n<p>\/\/ Event usage<\/p>\n<p>a.MyEvent += new EventHandler(MyHandler);<\/p>\n<p>\/\/ Overloaded operator usage<\/p>\n<p>MyClass c = a + b;<\/p>\n<p>Console.WriteLine(&#171;c.MyField = {0}&#187;, c.MyField);<\/p>\n<p>Console.ReadLine();<\/p>\n<p>}<\/p>\n<p>static void MyHandler(object sender, EventArgs e)<\/p>\n<p>{<\/p>\n<p>Console.WriteLine(&#171;Test.MyHandler&#187;);<\/p>\n<p>}<\/p>\n<p>internal class MyNestedClass<\/p>\n<p>{}<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<ol start=\"2\">\n<li>using System;<\/li>\n<\/ol>\n<p>namespace klass_2<\/p>\n<p>{<\/p>\n<p>\/\/\/ &lt;summary&gt;<\/p>\n<p>\/\/\/ Summary description for Class1.<\/p>\n<p>\/\/\/ &lt;\/summary&gt;<\/p>\n<p>public class Digit<\/p>\n<p>{<\/p>\n<p>public byte value;<\/p>\n<p>public Digit(byte value)<\/p>\n<p>{<\/p>\n<p>if (value &lt; 0 || value &gt; 9) throw new ArgumentException();<\/p>\n<p>this.value = value;<\/p>\n<p>}<\/p>\n<p>public Digit(int value): this((byte) value) {}<\/p>\n<p>public static implicit operator byte(Digit d)<\/p>\n<p>{<\/p>\n<p>return d.value;<\/p>\n<p>}<\/p>\n<p>public static explicit operator Digit(byte b)<\/p>\n<p>{<\/p>\n<p>return new Digit(b);<\/p>\n<p>}<\/p>\n<p>public static Digit operator+(Digit a, Digit b)<\/p>\n<p>{<\/p>\n<p>return new Digit(a.value + b.value);<\/p>\n<p>}<\/p>\n<p>public static Digit operator-(Digit a, Digit b)<\/p>\n<p>{<\/p>\n<p>return new Digit(a.value &#8212; b.value);<\/p>\n<p>}<\/p>\n<p>public static bool operator==(Digit a, Digit b)<\/p>\n<p>{<\/p>\n<p>return a.value == b.value;<\/p>\n<p>}<\/p>\n<p>public static bool operator!=(Digit a, Digit b)<\/p>\n<p>{<\/p>\n<p>return a.value != b.value;<\/p>\n<p>}<\/p>\n<p>public override bool Equals(object value)<\/p>\n<p>{<\/p>\n<p>return this == (Digit) value;<\/p>\n<p>}<\/p>\n<p>public override int GetHashCode()<\/p>\n<p>{<\/p>\n<p>return value.GetHashCode();<\/p>\n<p>}<\/p>\n<p>public override string ToString()<\/p>\n<p>{<\/p>\n<p>return value.ToString();<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>class Class1<\/p>\n<p>{<\/p>\n<p>static void Main(string[] args)<\/p>\n<p>{<\/p>\n<p>Digit a = (Digit)5;<\/p>\n<p>Digit b = (Digit)3;<\/p>\n<p>Digit plus = a + b;<\/p>\n<p>Digit minus = a-b;<\/p>\n<p>bool equals = (a == b);<\/p>\n<p>Console.WriteLine(&#171;{0} + {1} = {2}&#187;, a, b, plus);<\/p>\n<p>Console.WriteLine(&#171;{0} &#8212; {1} = {2}&#187;, a, b, minus);<\/p>\n<p>Console.WriteLine(&#171;{0} == {1} = {2}&#187;, a, b, equals);<\/p>\n<p>Console.ReadLine();<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<ol start=\"3\">\n<li>using System;<\/li>\n<\/ol>\n<p>class Point<br \/>\n{<br \/>\npublic double x, y;<\/p>\n<p>public Point() {<br \/>\nthis.x = 0;<br \/>\nthis.y = 0;<br \/>\n}<\/p>\n<p>public Point(double x, double y) {<br \/>\nthis.x = x;<br \/>\nthis.y = y;<br \/>\n}<\/p>\n<p>public static double Distance(Point a, Point b) {<br \/>\ndouble xdiff = a.x \u2013 b.x;<br \/>\ndouble ydiff = a.y \u2013 b.y;<br \/>\nreturn Math.Sqrt(xdiff * xdiff + ydiff * ydiff);<br \/>\n}<\/p>\n<p>public override string ToString() {<br \/>\nreturn string.Format(&#171;({0}, {1})&#187;, x, y);<br \/>\n}<br \/>\n}<\/p>\n<p>class Test<br \/>\n{<br \/>\nstatic void Main() {<br \/>\nPoint a = new Point();<br \/>\nPoint b = new Point(3, 4);<br \/>\ndouble d = Point.Distance(a, b);<br \/>\nConsole.WriteLine(&#171;Distance from {0} to {1} is {2}&#187;, a, b, d);<br \/>\n}<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>using System; namespace primer__klassa_1 { \/\/\/ &lt;summary&gt; \/\/\/ Summary description for Class1. \/\/\/ &lt;\/summary&gt;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27],"tags":[],"_links":{"self":[{"href":"http:\/\/studentpmr.ru\/index.php?rest_route=\/wp\/v2\/posts\/24590"}],"collection":[{"href":"http:\/\/studentpmr.ru\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/studentpmr.ru\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/studentpmr.ru\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/studentpmr.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=24590"}],"version-history":[{"count":1,"href":"http:\/\/studentpmr.ru\/index.php?rest_route=\/wp\/v2\/posts\/24590\/revisions"}],"predecessor-version":[{"id":24591,"href":"http:\/\/studentpmr.ru\/index.php?rest_route=\/wp\/v2\/posts\/24590\/revisions\/24591"}],"wp:attachment":[{"href":"http:\/\/studentpmr.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=24590"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/studentpmr.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=24590"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/studentpmr.ru\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=24590"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}