0% found this document useful (0 votes)
19 views

Referencecard

C# is a strongly typed language where every variable and expression has a specified type. Method signatures also define the type of parameters and return values. The .NET Framework includes built-in types like integers and strings as well as custom types to model problem domains. Variables must be declared with a type and are given a default value if not assigned one. Common basic types include integers, strings, Booleans, and objects. Variables should be named descriptively according to their purpose. Declarations are ended by assigning a relevant value of the specified type.

Uploaded by

api-302123663
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Referencecard

C# is a strongly typed language where every variable and expression has a specified type. Method signatures also define the type of parameters and return values. The .NET Framework includes built-in types like integers and strings as well as custom types to model problem domains. Variables must be declared with a type and are given a default value if not assigned one. Common basic types include integers, strings, Booleans, and objects. Variables should be named descriptively according to their purpose. Declarations are ended by assigning a relevant value of the specified type.

Uploaded by

api-302123663
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

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!

You might also like