Csharp/C Sharp/Language Basics/Expressions

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

Expressions 1

<source lang="csharp"> /*

* C# Programmers Pocket Consultant
* Author: Gregory S. MacBeth
* Email: gmacbeth@comporium.net
* Create Date: June 27, 2003
* Last Modified Date:
* Version: 1
*/

using System; namespace Client.Chapter_2___Operators_and_Excpressions {

 public class Expressions
 {
   static void Main(string[] args)
   {
     int   MyInt = 12345;
     int    MyInt2 = 10000;
     int    Sum = 0;
     long   MyLong = MyInt;
     short  MyShort = (short)MyInt;
     
     if (MyInt == MyInt2)
     {
       Sum = MyInt + MyInt2;
     }
     else
     {
       Sum = MyInt - MyInt2;
     }
   }
 }

}

      </source>


Expressions to calculate and display the circumference of a circle

<source lang="csharp"> /* Mastering Visual C# .NET by Jason Price, Mike Gunderloy Publisher: Sybex; ISBN: 0782129110

  • /

/*

 Example3_1.cs illustrates the use of
 expressions to calculate and display
 the circumference of a circle
  • /

public class Example3_1 {

 public static void Main()
 {
   const double Pi = 3.14159;
   double diameter = 2.5;
   // calculate the circumference
   double circumference = Pi * diameter;
   // display the circumference
   System.Console.WriteLine("Circumference = " + circumference);
 }

}

      </source>