Test 1

using System;

namespace   Hello
{
    class Program
    {
        static void Main()
        {
            Console.WriteLine("Hello , World ");
            Console.WriteLine("Computer Programing");
            Console.WriteLine("Praphai Saylam");
            Console.ReadLine();

       
        }
    }
}



Test 2

using System;

namespace DemoEscapeSequences{

    class Program  {
        static void Main() {
            Console.WriteLine("This line \tcontains two \ttabs");
            Console.WriteLine("This statement\ncontains a new line");
            Console.WriteLine("This statement sound three alerts\a\a\a");
            Console.ReadLine();
        }
    }
}



4.1โปรแกรมการแสดงค่าสูงสุดต่ำสุดของเลขจำนวนเต็ม


using System;

namespace IntegerRange
{
    class Program
    {


        static void Main()
        {


            Console.WriteLine("min sbyte = " + SByte.MinValue);

            Console.WriteLine("max sbyte = " + SByte.MaxValue);

            Console.WriteLine("min byte = " + Byte.MinValue);

            Console.WriteLine("min 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("max long = " + Int64.MaxValue);

            Console.WriteLine("min ulong = " + UInt64.MinValue);

            Console.WriteLine("max ulong = " + UInt64.MaxValue);

            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 Relation {


    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.5จะนำตัวดำเนินการแบบ short-circuit มาใช้


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("resule = {0}", result);
            Console.WriteLine("x = {0},y = {1}", x, y);


            Console.ReadLine();
        }
    }
}