Tutorial Addendum On C# - Allotment A - Data, Variables and Expressions

android appcolt wargamesios appcolt
 31 December 18:00   

    



    



    

Now let s analysis what accept abstruse in this area with a sample program:

    

 

    

class Variables {

    

accessible changeless abandoned Main() {

    

bool is_ok;

    

int n;

    

int num_of_sec;

    

continued number_of_sec_in_a_year;

    

float sqrt_s;

    

bifold sqrt_d;

    

burn c1, c2, c3;

    

burn cr, cn;

    



    

is_ok = true;

    

num_of_sec = 86400;

    

number_of_sec_in_a_year = 30458700;

    

sqrt_s = 1.4142F;

    

sqrt_d = 1.4142135623730950488016887242097;

    

c1 = a ;

    

c2 = A ;

    

c3 = 0 ;

    

cr =
;

    

cn =
;

    

n = 1;

    

System.Console.WriteLine("Value of is_ok = {0}.", is_ok);

    

System.Console.WriteLine("1 day = {0} seconds.", num_of_sec);

    

System.Console.WriteLine("1 year = {0} seconds.",

    

number_of_sec_in_a_year);

    

System.Console.WriteLine("Square basis of 2 (float) = {0}.",sqrt_s);

    

System.Console.WriteLine("Square basis of 2 (double) = {0}.",

    

sqrt_d);

    

System.Console.WriteLine("Some approved characters: {0}, {1}, {2}.",

    

c1, c2, c3);

    

System.Console.WriteLine("The acknowledgment character: {0}.", cr);

    

System.Console.WriteLine("The new band character: {0}.", cn);

    

n = 9;

    

System.Console.WriteLine("WriteLine() is acclimated {0} times.", n);

    

}

    

}

    



    



    

Output of the program will be:

    

 

    

Value of is_ok = True.

    

1 day = 86400 seconds.

    

1 year = 30458700 seconds.

    

Square basis of 2 (float) = 1.4142.

    

Square basis of 2 (double) = 1.4142135623731.

    

Some approved characters: a, A, 0.

    

.he acknowledgment character:

    

The new band character:

    

.

    

WriteLine() is acclimated 9 times.

    



    



    

Observations from this program:

    



        

  • Suffix F is acclimated in accurate "1.4142", because absolute literals are advised to be of

        

    64-bit size, which requires capricious blazon "double" to authority the value. The suffix F is

        

    forcing a absolute accurate to be of 32-bit size.

        



  •     

  • Literal "1.4142135623730950488016887242097" gets truncated and angled to "1.4142135623731"

        

    during the beheading of the appointment statement, because the bifold capricious name sqrt_d

        

    can alone authority about 14 decimal digits.

        



  •     

  • Variable "n" gets assigned alert in the program. Variables can be assigned to new values

        

    many times.

        



  •     



    



    

Advice: Abstain using "int" and "float". Use "long" and "double" instead. In the old days,

    

32-bit data requires beneath anamnesis to abundance and computer time to action than 64-bit data.

    

This is not absolutely true now, because today s computers are advised to abundance and

    

process data 64 $.25 at a time, not 32 $.25 at a time.

    



    

Expressions

    



    

So far we accept abstruse how to access data, abundance data, and retrieve data. The next move is

    

to apprentice how to accomplish data, like how to add two ethics calm to get the sum. This

    

requires the advice of data operations. Let s alpha with addition operations first. Other

    

types of operations will be discussed in after chapters.

    



    

There are 4 basal arithmetic operations that we can accomplish on basic and absolute data. Anniversary of

    

them is represented by appropriate attribute alleged operator. Bark is the operators of the 4

    

arithmetic operations:

    



        

  • "*": Multiplication

        



  •     

  • "/": Division

        



  •     

  • "+": Accession

        



  •     

  • "-": Subtraction

        



  •     



    



    

A individual addition operation can be entered into C# statements in a architecture alleged arithmetic

    

expression, with the afterward syntax:

    



    

arithmetic_expression:

    

accurate arithmetic_operator literal

    



    



    

Note that the literals acclimated in an addition announcement haveto be of the basic

    

or absolute data type. For example: 1 + 2, 1.4142 * 1.4142, 10 / 3.

    



    

 


Tags: program, times, system, character, store, value, requires, operations, float, console, seconds

 writeline, console, system, arithmetic, double, operations, character, literal, variables, square, seconds, float, program, expression, store, variable, times, value, requires, , system console, console writeline, square root, arithmetic expression, system console writeline, new line character, console writeline square, writeline square root,

Share Tutorial Addendum On C# - Allotment A - Data, Variables and Expressions:
Digg it!   Google Bookmarks   Del.icio.us   Yahoo! MyWeb   Furl  Binklist   Reddit!   Stumble Upon   Technorati   Windows Live   Bookmark

Text link code :
Hyper link code:

Also see ...

Permalink
Article In : Computers & Technology  -  c-sharp