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

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Operator/Ternary_Operator&amp;diff=5779&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/Operator/Ternary_Operator&amp;diff=5779&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/Operator/Ternary_Operator&amp;diff=5780&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Operator/Ternary_Operator&amp;diff=5780&amp;oldid=prev"/>
				<updated>2010-05-26T12:16:27Z</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;==Prevent a division by zero using the ? operator==&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 Example { &lt;br /&gt;
  public static void Main() { &lt;br /&gt;
    int result; &lt;br /&gt;
 &lt;br /&gt;
    for(int i = -5; i &amp;lt; 6; i++) { &lt;br /&gt;
      result = i != 0 ? 100 / i : 0; &lt;br /&gt;
      if(i != 0)  &lt;br /&gt;
        Console.WriteLine(&amp;quot;100 / &amp;quot; + i + &amp;quot; is &amp;quot; + result); &lt;br /&gt;
    } &lt;br /&gt;
  } &lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;100 / -5 is -20&lt;br /&gt;
100 / -4 is -25&lt;br /&gt;
100 / -3 is -33&lt;br /&gt;
100 / -2 is -50&lt;br /&gt;
100 / -1 is -100&lt;br /&gt;
100 / 1 is 100&lt;br /&gt;
100 / 2 is 50&lt;br /&gt;
100 / 3 is 33&lt;br /&gt;
100 / 4 is 25&lt;br /&gt;
100 / 5 is 20&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Simplest Data type cast operator==&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 MyDataType&lt;br /&gt;
{&lt;br /&gt;
   public static explicit operator int(MyDataType li)   // Convert type&lt;br /&gt;
   {&lt;br /&gt;
      Console.WriteLine(&amp;quot;explicit operator int&amp;quot;);&lt;br /&gt;
      return 0;&lt;br /&gt;
   }&lt;br /&gt;
   public static explicit operator MyDataType(int x)    // Convert type&lt;br /&gt;
   {&lt;br /&gt;
      Console.WriteLine(&amp;quot;public static explicit operator MyDataType&amp;quot;);&lt;br /&gt;
      return new MyDataType();&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;
      MyDataType d = (MyDataType)5;&lt;br /&gt;
      int Five = (int)d;&lt;br /&gt;
      Console.WriteLine(Five);&lt;br /&gt;
   }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;public static explicit operator MyDataType&lt;br /&gt;
explicit operator int&lt;br /&gt;
0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The ? Operator==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;OL&amp;gt;&amp;lt;LI&amp;gt;The ? operator is often used to replace certain types of if-then-else constructions.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;The ? is called a ternary operator because it requires three operands.&amp;lt;/LI&amp;gt;&amp;lt;/OL&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;It takes the general form&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;Exp1 ? Exp2 : Exp3;&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;OL&amp;gt;&amp;lt;LI&amp;gt;where Exp1 is a bool expression, and Exp2 and Exp3 are expressions.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;The type of Exp2 and Exp3 must be the same.&amp;lt;/LI&amp;gt;&amp;lt;/OL&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The value of a ? expression is determined like this:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;OL&amp;gt;&amp;lt;LI&amp;gt;Exp1 is evaluated.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;If it is true, then Exp2 is evaluated and becomes the value of the entire ? expression.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;If Exp1 is false, then Exp3 is evaluated, and its value becomes the value of the expression.&amp;lt;/LI&amp;gt;&amp;lt;/OL&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The ternary operator==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;class MainClass&lt;br /&gt;
{&lt;br /&gt;
  public static void Main()&lt;br /&gt;
  {&lt;br /&gt;
    int result;&lt;br /&gt;
    result = 10 &amp;gt; 1 ? 20 : 10;&lt;br /&gt;
    System.Console.WriteLine(&amp;quot;result = &amp;quot; + result);&lt;br /&gt;
    result = 10 &amp;lt; 1 ? 20 : 10;&lt;br /&gt;
    System.Console.WriteLine(&amp;quot;result = &amp;quot; + result);&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;result = 20&lt;br /&gt;
result = 10&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Use ternary operator in Console.WriteLine function==&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 MainClass&lt;br /&gt;
{&lt;br /&gt;
   static void Main()&lt;br /&gt;
   {&lt;br /&gt;
      int x = 10, y = 9;&lt;br /&gt;
      Console.WriteLine(&amp;quot;x is{0} greater than y&amp;quot;,&lt;br /&gt;
                            x &amp;gt; y          // Condition&lt;br /&gt;
                            ? &amp;quot;&amp;quot;           // Expression 1&lt;br /&gt;
                            : &amp;quot; not&amp;quot;);     // Expression 2&lt;br /&gt;
      y = 11;&lt;br /&gt;
      Console.WriteLine(&amp;quot;x is{0} greater than y&amp;quot;,&lt;br /&gt;
                            x &amp;gt; y          // Condition&lt;br /&gt;
                            ? &amp;quot;&amp;quot;           // Expression 1&lt;br /&gt;
                            : &amp;quot; not&amp;quot;);     // Expression 2&lt;br /&gt;
   }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;x is greater than y&lt;br /&gt;
x is not greater than y&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>