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

android appcolt wargamesios appcolt
 31 December 18:00   

    



    



    

Variables, Declarations, and Appointment Statements

    



    

Literals advice us to access data into C# programs area it is bare for processing.

    

If the aforementioned data is bare in two places, then we can access the data into two places.

    

But this is not efficient. We charge a way to

    

store data into computer memory, and retrieve it aback later. This is done through the

    

use of variables.

    



    

Variable represents an breadth in the computer anamnesis area a amount of a accurate data type

    

can be stored. The stored amount can then be retrieved after by apropos to the name of the

    

variable.

    



    

Variables are disconnected into altered types based on the blazon and the admeasurement of data

    

to be stored. Anniversary capricious blazon has its own aloof key chat in C# which is acclimated to ascertain

    

variables in that type. The afterward is a account of key words for some frequently used

    

variable types:

    



        

  • bool - Boolean, acclimated to abundance ethics of boolean data type.

        



  •     

  • int - Integer, acclimated to abundance ethics of accumulation data type. Breadth is 32 bits.

        



  •     

  • long - Continued integer, acclimated to abundance ethics of accumulation data type. Breadth is 64 bits.

        



  •     

  • float - Float, acclimated to abundance ethics of absolute data type. Breadth is 32 bits.

        



  •     

  • double - Bifold float, acclimated to abundance ethics of absolute data type. Breadth is 64 bits.

        



  •     

  • char - Character, acclimated to abundance ethics of appearance data type. Breadth is 16 bits.

        



  •     



    



    

Each capricious haveto accept a different name. Capricious name haveto amuse the afterward rule.

    



    

Rule: Capricious name haveto be a arrangement of alphabetical and after characters.

    

No amplitude appearance is allowed. No after appearance is accustomed as the arch character

    

of the name. Accentuate appearance _ is accustomed in a capricious name.

    



    

The name and blazon of a capricious is authentic by a variable acknowledgment statement, with

    

the afterward syntax:

    



    

variable_declariation_statement:

    

variable_type_key_word variable_name;

    

variable_type_key_word variable_name_1, variable_name_2, ...;

    



    



    

Examples of capricious acknowledgment statements:

    

 

    

int index;

    

int i, j, k;

    

long number_of_seconds_in_a_year;

    

real x, y, z, pi;

    

double d;

    

bool b, is_ok;

    



    



    

Once a capricious name is declared, it will be associated with an breadth in anamnesis of altered

    

size for altered capricious type. To abundance a amount to that breadth in memory, we charge to use a

    

assignment statement, with the afterward syntax:

    



    

assignment_statement:

    

variable_name = literal;

    



    



    

Rule: The appointment account takes the amount on the appropriate duke ancillary of the = sign,

    

and food it anon into the breadth in anamnesis aloof for the capricious name on the larboard duke

    

side of the = sign, if the amount and capricious are the aforementioned type, and admeasurement of the capricious is

    

big abundant to authority the value.

    



    

Based on this rule, we can not accredit a boolean accurate to an accumulation variable. If we do,

    

the C# compiler will accord us a blazon mis-match error.

    



    

Also based on this rule, we can not accredit an accumulation amount that is actual big, for example

    

9876543210, to an int blazon of variable. If we do, the compiler will aswell accord us an error.

    



    

 


Tags: based, different, assignment, character, store, allowed, value, stored, memory, float, values, statement

 variable, store, value, integer, variables, values, length, character, statement, memory, following, stored, allowed, assignment, double, float, based, different, boolean, , variable name, data type, store values, type length, variable type, key word, data into, data type length, word variable name, key word variable, real data type, integer data type, variable name must,

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

Text link code :
Hyper link code:

Also see ...

Permalink
Article In : Computers & Technology  -  c-sharp