C-Sharp
Programing Language
A Book To Help You…(Basic)
Part-I
By Neha Chandel
Introducing C-#
C#, also known as C-sharp, is a programming language
introduced by Microsoft. C# contains features similar to Java and C++. It is specially designed to
work with Microsoft’s DotNet platform. Object –Oriented Programming (OOP)
is one of the most popular methodologies in software development. It offers a
powerful model for creating computer programs. It speeds the program
development process, improves maintenance and enhances reusability of programs.
Object-orientation is a type of
methodology used for building software application. An object-oriented program
consists of classes, object, and method. The object-oriented methodology in software
development revolves around a single concept called the object. Software
is developed by breaking the application into commonent object. These objects
interact with each other when the whole application is put together.
Characteristics of the Object-Oriented Approach :
·
Realistic Modeling
·
Reusability
·
Resilience to Change
Phases of Object Orientation
·
The Analysis phase
·
The Design phase
·
The Implementation phase
Compilers
All languages have a vocabulary, which is a list of
words that have a specific meaning in that languages. Languages also have their
own grammar rules, which state the rules for combining words to form sentences.
This is what ensure that whatever is
spoken in a particular language is interpreted similarly by all people who
understand the language.
A compiler is a special program that process the
statements written in a particular programming language and converts them into
machine language. Like everything else in the compiler also follows the
input-process-output (I-P-O) cycle. It takes the programming language instructions as input. It process these
instructions to convert them to machine language instructions as input. It
process these instructions to convert them to machine language. These
instructions can then be executed by the computer. This process of conversion
is called compilation. For each programming language, there is a different
compiler available. For example, for compiling a program written in the C
language, you require a C compiler. For a Java program, you require a java
compiler, for C # programs, you will use the CSC compiler.
OBJECTS
An object is an entity that may have a physical
boundary. However, it should have the following
characteristics:
·
State
·
Behavior
·
Identity
Class
A class consists of a set of object that share a common
structure and behavior.Like Birds is a class that contain all peacook,
sparrow,and all other birds.
Classes in C #
Consider the following code example, Which define a
class:
Public class Hello
{
Public static void Main
(string args[])
{
System.Console.Writeline(“This
is our class example and the class name is Hello! ”);
}
}
The preceding class
declaration provides a method Main() that will display the message “This is our
class example and the class name is Hello” on your screen. The parts of the
preceding code need to be examined .
The Main Function
The first line of code that
a c# compiler looks for in the source file compiled is the Main() function.
This function is the entry point of the application.
The Main() function is
ideally used to create objects and invoke member functions.
The class Keyword
The class keyword is used to
declare a class keywords are reserved words that have a special meaning. The braces, known as delimiters, are used to
indicate the start and end of a class body.
Example :
Class Hello
{
……
}
The class names should
follow certain naming conventions or guidelines. A class name :
·
Should be meaningful (Strongly recommended).
·
Should ideally be a noun
·
Can use either the first letter is cpital and the
rest of the letter are in lower case. Or in
all in lower case.
Rules for Naming Classes in
C#
·
Name of class ust begain with a letter. This letter
may be followed by a sequence of letter, digits (0-9), or _ the first character
in a class name cannot be a digit.
·
Must not contain any
embedded space or symbol like ? _ + ! @ # % ^ & * () {} [] ,:;”/and
\ however, an underscore(“_”) can be used wherever a space is required.
·
Must not use a keyword for a class name. For
example, you cannot declare a class called public.
System.Consloe.WriteLine()
Console is a class that
belongs to the System namespace. A namespace is a collection of class. The
System namespace contains the method
Writerline(), which displays the enclosed text on the screen. The Console class
has other method, which are used for various input/output operation. The
character. Is used to access the function WriteLine(), which is coded in the
Console class of the System namespace.
The preceding line canalso
be written as Console.Writeline() if the statement using System is included as
the first line of code.The Following code is an example of Console.WriteLine
():
Console.WriteLine(“Hello
World”);
The Preceding code will display on the screen.
Hello World