Int, float, double, decimal : Variable Definition « Language Basics « C# / C Sharp






Int, float, double, decimal

Int, float, double, decimal
/*
Learning C# 
by Jesse Liberty

Publisher: O'Reilly 
ISBN: 0596003765
*/
 using System;
 public class IntFloatDoubleDecValues
 {
     static void Main()
     {
         int firstInt, secondInt;
         float firstFloat, secondFloat;
         double firstDouble, secondDouble;
         decimal firstDecimal, secondDecimal;

         firstInt = 17;
         secondInt = 4;
         firstFloat = 17;
         secondFloat = 4;
         firstDouble = 17;
         secondDouble = 4;
         firstDecimal = 17;
         secondDecimal = 4;
         Console.WriteLine("Integer:\t{0}\nfloat:\t\t{1}",
             firstInt/secondInt, firstFloat/secondFloat);
         Console.WriteLine("double:\t\t{0}\ndecimal:\t{1}",
             firstDouble/secondDouble, firstDecimal/secondDecimal);
         Console.WriteLine(
           "\nRemainder(modulus) from integer division:\t{0}",
             firstInt%secondInt);

     }
 }

           
       








Related examples in the same category

1.Declaring a variable.
2.Initializing a variable.
3.Variable default nameVariable default name
4.Heap and Stack Memory
5.Two reference type variables may refer (or point) to the same objectTwo reference type variables may refer (or point)
               to the same object
6.Create a 4-bit type called NybbleCreate a 4-bit type called Nybble
7.Use new with a value typeUse new with a value type
8.Init variableInit variable
9.An attempt to reference an uninitialized variable
10.Illustrates variable scope
11.Demonstrate the use of readonly variablesDemonstrate the use of readonly variables
12.Uninitialized Values
13.Demonstrate dynamic initializationDemonstrate dynamic initialization
14.Demonstrate block scopeDemonstrate block scope
15.Demonstrate lifetime of a variableDemonstrate lifetime of a variable
16.This program attempts to declared a variable in an inner scope
17.Demonstrate castingDemonstrate casting
18.A promotion surpriseA promotion surprise
19.Using casts in an expressionUsing casts in an expression
20.Create an implication operator in C#Create an implication operator in C#
21.declaring a reference type variable and creating an object the variable will reference
22.Definite Assignment and ArraysDefinite Assignment and Arrays
23.Variable Scoping and Definite Assignment:Definite AssignmentVariable Scoping and Definite Assignment:Definite Assignment