วันศุกร์ที่ 5 สิงหาคม พ.ศ. 2554

โปรแกรม 4.5

using System;
namespace ShortCircuit
{
    class Program
    {
        static void Main(string[] args)
        {
            int x = 4;
            int y = 5;
            Console.WriteLine("x = {0}, y = {1}", x, y);
            bool result = true || (++x == y);
            Console.WriteLine("result = {0}", result);
            Console.WriteLine("x = {0}, y = {1}", x, y);

            result = true && (++x == y);
            Console.WriteLine("result = {0}", result);
            Console.WriteLine("x = {0}, y = {1}", x, y);
            Console.ReadLine();
        }
    }
}

โปรแกรม 4.2

using System;
namespace DisplaySomeMoney
{
    class Program
    {
        static void Main()
        {
            double someMoney = 39.45;
            Console.Write("The money is ");
            Console.WriteLine(someMoney);
            double someMoney1 = 39.46;
            Console.Write("The money is ");
            Console.WriteLine(someMoney1);
            double someMoney2 = 39.47;
            Console.Write("The money is ");
            Console.WriteLine(someMoney2);
            double someMoney3 = 39.48;
            Console.Write("The money is ");
            Console.WriteLine(someMoney3);
            double someMoney4 = 39.49;
            Console.Write("The money is ");
            Console.WriteLine(someMoney4);
            double someMoney5 = 39.50;
            Console.Write("The money is ");
            Console.WriteLine(someMoney5);
            Console.ReadLine();
        }
    }
}

โปรแกรม 4.4

using System;
namespace Relational {
    class Program {
        static void Main(string[] args){
            int x = 17;
            int y = 5;
            Console.WriteLine("{0} =={1}={2}", x, y, x == y);
            Console.WriteLine("{0} !={1}={2}", x, y, x != y);
            Console.WriteLine("{0} < {1}={2}", x, y, x < y);
            Console.WriteLine("{0} <={1}={2}", x, y, x <= y);
            Console.WriteLine("{0} > {1}={2}", x, y, x > y);
            Console.WriteLine("{0} >= {1}={2}", x, y, x >= y);
            Console.ReadLine();
          }
      }
  }


โปรแกรม4.1

using System;
namespace integerRange {
    class Program {
   
        static void Main()  {
            Console.WriteLine("min sbte = " + SByte.MinValue);
            Console.WriteLine("max sbte = " + SByte.MaxValue);
            Console.WriteLine("min byte = " + Byte.MinValue);
            Console.WriteLine("max byte = " + Byte.MaxValue);
            Console.WriteLine("min short = " + Int16.MinValue);
            Console.WriteLine("max short = " + Int16.MaxValue);
            Console.WriteLine("min ushort = " + UInt16.MinValue);
            Console.WriteLine("max ushort = " + UInt16.MaxValue);
            Console.WriteLine("min int = " + Int32.MinValue);
            Console.WriteLine("max int = " + Int32.MaxValue);
            Console.WriteLine("min uint = " + UInt32.MinValue);
            Console.WriteLine("max uint = " + UInt32.MaxValue);
            Console.WriteLine("min long = " + Int64.MinValue);
            Console.WriteLine("maxlong = " + Int64.MaxValue);
            Console.WriteLine("min ulong = " + UInt64.MinValue);
            Console.WriteLine("max ulong = " + UInt64.MaxValue);
            Console.ReadLine();
         }
     }
 }