Senin, 08 April 2013

C# CODE for CALCULATOR

using System;
namespace Calculation
{
    class CalculateNumber
    {
        int Number1, Number2;
        char option;
        int Result;
    public void Number()
    {
            Console.WriteLine("Enter the First number");
            Number1 = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Enter the second number");
            Number2 = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Main Menu");
            Console.WriteLine("1.Addition");
            Console.WriteLine("2.Subtraction");
            Console.WriteLine("3.Multiplication");
            Console.WriteLine("4.Division");
            Console.WriteLine("Enter the Operation you want to perform");
            option = Convert.ToChar(Console.ReadLine());
    switch (option)
    {

            case '1':
                Result = Number1 + Number2;
                Console.WriteLine("The result of addition is:{0}", Result);
                break;
            case '2':
                Result = Number1 - Number2;
                Console.WriteLine("The result of subtraction is:{0}", Result);
                break;
            case '3':
                Result = Number1 * Number2;
                Console.WriteLine("The result ofmultiplication is:{0}", Result);
                break;
            case '4':
                Result = Number1 / Number2;
                Console.WriteLine("The result of division is:{0}", Result);
                break;
            default:
            Console.WriteLine("Invalid Option");
            break;
        }
        Console.ReadLine();
    }
}
    class ClassMain
    {
        static void Main(string[] args)
        {
            CalculateNumber obj = new CalculateNumber();
            obj.Number();
        }
    }

C# better than JAVA ??

  • JAVA

Not everything in Java is an object. There is a special group of data types (also known as primitive types) that will be used quite often in your programming. For performance reasons, the designers of the Java language decided to include these primitive types. 

Creating an object using new isn't very efficient because new will place objects on the heap. This approach would be very costly for small and simple variables. Instead of create variables using new, Java can use primitive types to create automatic variables that are not references. The variables hold the value, and it's place on the stack so its much more efficient.

Java determines the size of each primitive type. These sizes do not change from one machine architecture to another (as do in most other languages). This is one of the key features of the language that makes Java so portable.
Take note that all numeric types are signed. (No unsigned types).

Finally, notice that each primitive data type also has a "wrapper" class defined for it. This means that you can create a "nonprimitive object" (using the wrapper class) on the heap (just like any other object) to represent the particular primitive type.
For example:
int i = 5;
Integer I = new Integer(i);
OR
Integer I = new Integer(5);

Data Types and Data Structures

Primitive Type Size Minimum Value Maximum Value Wrapper Type
char   16-bit     Unicode 0   Unicode 216-1   Character
byte   8-bit     -128   +127   Byte
short   16-bit     -215
(-32,768)
  +215-1
(32,767)
  Short
int   32-bit     -231
(-2,147,483,648)
  +231-1
(2,147,483,647)
  Integer
long   64-bit     -263
(-9,223,372,036,854,775,808)
  +263-1
(9,223,372,036,854,775,807)
  Long
float   32-bit     32-bit IEEE 754 floating-point numbers   Float
double   64-bit     64-bit IEEE 754 floating-point numbers   Double
boolean   1-bit     true or false   Boolean
void   -----     -----     -----     Void


  • C# 

    C# represents all primitive data types as objects, it is possible to call an object method on a primitive data type. 

    For example:

    static void Main()
    {
        int i = 10;
        object o = i;
        System.Console.WriteLine(o.ToString());
    }   

     

    C# PRIMITIVE TYPE
    FCL DATA TYPE
    DESCRIPTION
    object
    System.Object
    Ultimate base type of all other types.
    string
    System.String
    A sequence of Unicodecharacters.
    decimal
    System.Decimal
    Precise decimal with 28 significant digits.
    bool
    System.Boolean
    A value represented as true or false.
    char
    System.Char
    A 16-bit Unicode character.
    byte
    System.Byte
    8-bit unsigned integral type.
    sbyte
    System.SByte
    8-bit signed integral type.
    short
    System.Int16
    16-bit signed integral type.
    int
    System.Int32
    32-bit signed integral type.
    long
    System.Int64
    64-bit signed integral type.
    ushort
    System.UInt16
    16-bit unsigned integral type.
    uint
    System.UInt32
    32-bit unsigned integral type.
    ulong
    System.UIint64
    64-bit unsigned integral type.
    single (float)
    System.Single
    Single-precision floating-point type.
    double
    System.Double
    Double-precision floating-point type.