Learn C# programming / PDF
Learn c# programming / PDF
Structure of a C# program
For the
first program, below listing shows the near-minimal amount of code necessary to
write.
/*
File
name : FirstProgram.cs
Author
:Ali Can
*/
using System;
// Program start class
public Class
FirstProgram
{
public static void main()
{
Console.WriteLine(“This
Is My First C# Program “);
}
}
A simple
C# program consist of the following structures.
- contains classes, structures and types.
- A class has
o Data(fields)
o Behaviors(methods)
- A C# application can consist of many files
- Have a Main method as an entry point
- The .NET Framework provides many classes which are organized in
namespaces
- Most common namespace is System
- Refer to classes by their namespace
- Namespaces must be fully qualified without Using directive
System.Console.WriteLine(“This
My First C# Program “);
Using directive allows for less typing
using System;
…
Console.WriteLine(“This
My First C# Program “);
C# uses
class to define or declare objects. They describe the attributes and behavior
of an object. An object is anything that has attributes and behavior. Objects
are building blocks of the C# programming language. It has a starting object.
The
identifier, or name , of a class follows the class keyword. This is called FirstProgram.
Left and
right braces indicate the beginning and ending, respectively of a block.
There is a
method declaration in the given program. This is Main ()
method. Every program has a Main ()
method that is the starting point for the program. C# Main ()
methods always have static modifier.
In C# there are two types of objects:
Static
instance.
Instance objects are formally declared, and there can be many
of the same type with different attributes.
However ,
there can be only a single
copy of static object in existence for a
given program. The
only way to execute a method without an instance of its containing object is if
that method is static.
The Console class enables programs to
output information to the computer’s standard output. Class Console provides methods that allow C#
programs to display strings and other types of information in the Windows
command prompt.
Method Console.WriteLine displays a line of
text in the console window, its argument in the parentheses (“This is My First
C# Program”) and the semicolon (;) is called statement.
Identifiers and keywords
Identifiers are names of various program
elements in the code that uniquely identify an element. They are name of things like variables or
fields.
There are
essentially two forms of naming conventions in C#.
The first is pascal casing, where the first
letter of each word in a name is capitalized, such as
HelloWorld
PersonelNumber.
Pascal
casing is normally used in all instance except for
parameters and private fields of classes.
In the case of private class fields and method parameters, use camel casing , where the first letter
of the first word is lowercase and the first letter of subsequent words is
capitalized............
Learn c# programming / PDF
0 commentaires: