C# Programming
Types, Variables,
and Values
C# is a strongly-typed language. Every
variable and constant has a type, as
does every expression that evaluates
to a value.
Every method signature specifies a
type for each input parameter and for
the return value. The .NET Framework
class library defines a set of built-in
numeric types as well as more
complex types that represent a wide
variety of logical constructs.
A typical C# program uses types from
the class library as well as userdefined types that model the
concepts that are specific to the
program's problem domain.
The information stored in a type can
include the following, and more:
The storage space that a
variable of the type requires.
The maximum and minimum
values that it can represent.
The members (methods,
fields, events, and so on) that
it contains.
When you declare a variable or constant in a program, you must
either specify its type or use the var keyword to let the compiler
infer the type. If a variable type is not assigned a value, it is assigned
the default value. Below are some basic types:
Possible Types
Bool
Byte
Short
Int
Long
String
Object
Possible Values
True or False
0 to 255
-32,768 to 32,767
-2,147,483,648 to 2,147,483,647
-9,223,372,036,854,775,808 to
9,223,372,036,854,775,807
A string of Unicode characters.
An object.
Default Values
False
0
0
0L
0
null
null
Naming a variable or constant is up to your imagination. Try to name
variables according to their intended purposes and goals. For example,
a variable storing the number of eggs in the fridge should not be
named shoes. Typical naming convention for multi-word names is to
lowercase the first word, and capitalize the first letter of every word
thereafter.
End your declaration by assigning a value to the type and name you
have created. The value should be relevant to the type you have
specified, otherwise you might generate an error!
Some Examples of Declarations
Int number = 100;
String myName = John;
Bool isItTrue = true;
Beyond The Basics
After a variable is declared, it cannot be re-declared with a new type, and it
cannot be assigned a value that is not compatible with its declared type. For
example, you cannot declare an int and then assign it a Boolean value of true.
However, values can be converted to other types through a type conversion.
More information available online!
Search Microsoft C#
Programming
Dont forget to add a semi-colon at the end of
declarations!