Sponsored Ad

Monday, September 20, 2010

Demo of Binary Operations in C#

Binary Operations are performed between two operands. here is few C# binary operation and their results.

Demo of Binary Operations in C#

Code:

using System;
using System.Text;
using System.Data;
namespace Console_App
{
    public class clsBinaryOperations
    {
        public static void Main()
        {
            try
            {
                int value1, value2, result;
                float floatResult;

                Console.WriteLine("Program for Binary Operations in C#");

                value1 = 5;
                value2 = 9;

                Console.WriteLine("Value of value1: {0}", value1);
                Console.WriteLine("Value of value2: {0}", value2);

                result = value1 + value2;
                Console.WriteLine("Result of value1+value2: {0}", result);

                result = value1 - value2;
                Console.WriteLine("Result of value1-value2: {0}", result);

                result = value1 * value2;
                Console.WriteLine("Result of value1*value2: {0}", result);

                result = value1 / value2;
                Console.WriteLine("Result of value1/value2: {0}", result);

                floatResult = (float)value1 / (float)value2;
                Console.WriteLine("Result of (float)value1 / (float)value2: {0}", floatResult);

                result = value1 % value2;
                Console.WriteLine("Result of  value1%value2: {0}", result);

                result += value1;
                Console.WriteLine("Result of  result+=value1: {0}", result);
            }
            catch (Exception ex)
            {
                //handle exception here
            }
            Console.ReadLine();
        }
    }
}

No comments:

Post a Comment

Sponsored Ad

Development Updates