BASIC OF C# PROGRAMMING FOR BEGINNERS – PART :
I
Introduction
In this article we see the Basic of concepts of C#
- Identifier
- Keywords
- Variables
Identifier
An identifier, in C#,
is the user-defined name of a program element. It can be a namespace, class,
method, variable or interface. Identifiers in C# are case-sensitive.
An identifier name
should indicate the meaning and usage of the element being referred.
C# is a programming language that is compiled
and has its implementation such that the identifiers are only compile-time
entities. During run time, each identifier will be referred by its reference to
the memory address and offset the compiler assigned to its textual identifier
token.
Microsoft recommends
the use of Camel or Pascal notations, along with semantics, for was used prior
to .NET programming. For example, "employeeAge" might represent Camel
notation wherein the first letter of all the words is capitalized except the
first word. Camel notation is used to name private members, fields and
parameters. "EmployeeAge" is an identifier in Pascal notation, as all
the words in the identifier begin with an upper-case letter.
The rules to be
followed while using an identifier include:
- It can start only with a letter
of the alphabet or underscore(_), but not a number
- It can be a combination of
numbers, letters, connectors, Unicode escape sequence, etc.
- It cannot be a C# keyword
- It should not contain white
space
- It cannot have more than 511
characters
- It cannot have two consecutive
underscores in its name because such identifiers are used for the
implementation
- More than one identifier with
the same name cannot be declared within a single scope
An identifier prefixed
with "@" is called a verbatim identifier. Although prefixing
"@" allows for the use of keywords, which helps in interfacing with
other programming languages, it is not a recommended practice.
Keywords
Keywords are predefined, reserved identifiers that have special meanings to the compiler. They cannot be used as identifiers in your program unless they include @ as a prefix. For example, @if is a valid identifier but if is not because if is a keyword.
Keywords are predefined, reserved identifiers that have special meanings to the compiler. They cannot be used as identifiers in your program unless they include @ as a prefix. For example, @if is a valid identifier but if is not because if is a keyword.
Following Table list the different
reserved and contextual keywords
|
Reserved Keywords
|
||||||
|
abstract
|
as
|
base
|
bool
|
break
|
byte
|
case
|
|
catch
|
char
|
checked
|
class
|
const
|
continue
|
decimal
|
|
default
|
delegate
|
do
|
double
|
else
|
enum
|
event
|
|
explicit
|
extern
|
false
|
finally
|
fixed
|
float
|
for
|
|
foreach
|
goto
|
if
|
implicit
|
in
|
int
|
interface
|
|
internal
|
is
|
lock
|
long
|
namespace
|
new
|
null
|
|
object
|
operator
|
out
|
override
|
params
|
private
|
protected
|
|
public
|
readonly
|
ref
|
return
|
sbyte
|
sealed
|
short
|
|
sizeof
|
stackalloc
|
static
|
string
|
struct
|
switch
|
this
|
|
throw
|
true
|
try
|
typeof
|
uint
|
ulong
|
unchecked
|
|
unsafe
|
ushort
|
using
|
virtual
|
volatile
|
void
|
while
|
Contextual
Keywords
|
||||||
|
add
|
alias
|
ascending
|
descending
|
dynamic
|
from
|
get
|
|
global
|
group
|
into
|
join
|
let
|
orderby
|
partial
|
|
remove
|
select
|
set
|
value
|
where
|
yield
|
|
Variables
A variable, in C#, refers to a location in
memory in which an application can store its data. Variables are used to store
the result of calculations and hold the values that can change during the
execution of a program. Variables are also used to place and retrieve the data
forms an expression.
C# language is designed to be "type-safe," which helps ensure that the value stored in a variable is of the appropriate type. The type of a variable specifies what kind of data it can hold. This feature helps to reduce the burden from the programmer by guaranteeing the data's type safety.
C# expects the data type of a variable to be specified during declaration, which helps to allocate the memory for the variable during run time. In order to maintain the integrity of the data stored in a variable, C# defines a set of rules that dictate the permissible operations that can be performed on the variable.
C# language is designed to be "type-safe," which helps ensure that the value stored in a variable is of the appropriate type. The type of a variable specifies what kind of data it can hold. This feature helps to reduce the burden from the programmer by guaranteeing the data's type safety.
C# expects the data type of a variable to be specified during declaration, which helps to allocate the memory for the variable during run time. In order to maintain the integrity of the data stored in a variable, C# defines a set of rules that dictate the permissible operations that can be performed on the variable.
For example
int x;
x=25;
In this example we declare a x
variable with integer data type and assign a value of 25 by using = operator
A variable can be declared as local or
class variable. Local Variable exist within the scope of a given method in a
class, Class variables exist the entire Lifetime of the object instance of the
class
No comments:
Post a Comment