Menu

Monday, 30 October 2017

Writing the first program

class FirstProgram
{
  static void Main()
   {
      System.Console.WriteLine("My first program in csharp..!");
    }
}


output:  My first program in csharp..!

Note: To compile the program we need 'Developer Command Prompt for VS' which we will get automatically after installing visual studio.

What is System.Console.WriteLine ?

  •  Console is a predefined class under the libraries of our language which provides with a set of static members to perform IO operations on standard I/O devices.
  • The Console class contains methods like WriteLine, Write, ReadLine, Read, ReadKey to perform I/O operations.
  • System is a namespace where a namespace is a logical container of types like Class, Structure, Interface, Enum and Delegate.

What is Namespace?

  • Namespaces are used as logical containers in programming languages. 
  • Every predefined type in our libraries is under some namespace.
  • We can also define our types under some namespaces and we will check out that process later.
  • If a type is defined under any namespace then it is must to prefix with that particular namespace while consuming that type.
  •  To overcome the above problem we provided with an option known as importing a namespace with the help of "using directive".
  • If we import a namespace into the program we can start consuming all the types under that namespace without prefixing it each and every time.
Example: using System;

Now the program can be written as, 

using System;

class FirstProgram
{
  static void Main()
   {
      Console.WriteLine("My first program in csharp..!");
    }
}





Programming in Csharp

Rules to be followed while writing code:

  1. It's a case sensitive language. All keywords must be in lower case. While consuming libraries all names must be in a proper case. For example, WriteLine, ReadLine  etc... While defining our own classes and members we can follow any casing policy but still proper-case is recommended.
  2. Program should be saved with ".cs" extension.
  3. The filename can be any but better to take class name as filename.

Syntax to define a class:

[<modifiers>] class <Name>
{
  -Members
}

[] means optional
<> means we can write anything in it.

Syntax to define Main() in class :

static void Main([string[] args])
{
   statements to execute;
}

Main() method must be static if at all we want to start the execution from here without creating instance of the class.

Main() method doesn't return any value, so to specify that we use 'void' keyword.

If required we can pass parameter to Main() method but it should be of type String arrays only.

Thursday, 26 October 2017

C# Program Structure

class Example
{
     - collection of members  // Static and Non-Static members

    static void Main([string[] args]) 
{
    - statements;
}

}

A C# program contains the following parts in it:-

  • Declaration of Namespace
  • Class
  • Class members
  • Main method    // Entry point of the program
  • Statements and Expressions
  • Comments

Sample Program :

using System;

class Example
{
static void Main(string[] args)
{
  Console.WriteLine("Welcome to Csharp Programming...!");
}
}

output: Welcome to Csharp Programming...!



Now let us learn various parts of the above program :
  • using System in the first line is used to include the System namespace in the program. This namespace has Console class which has many methods like writeline(), readline() etc.. 
  • class is collection of members.
  • Main() is the point from where the execution starts.
  • Console is a class present under System namespace.
  • WriteLine is a method defined under console class. Moreover, it is a printing statement.

Environment setup for C#

TOOLS REQUIRED FOR CREATING C# PROGRAMMING :

We already know that C# is a part of  .Net framework which is used for developing applications. So, let us first get some knowledge about .Net framework then we will discuss about the tools that are required for running C# program. Let us know how C# related to this framework.

WHAT IS .NET FRAMEWORK?

It is a product of Microsoft which is used for developing platform independent(portable) and object-oriented(Security & Reusability) applications. The following applications can be developed by using this framework,
  • Desktop Applications
  • Web Applications
  • Mobile Applications
To develop the above applications we are provided with the following things under .NET.

1)Programming Languages  :
  •  C#
  • VB.Net
  •  F#.Net
  •  J#.Net
  •  COBOL .Net etc...

2)Technologies:

  •  ADO.Net (Database Communication)
  •  ASP.NET

3)Servers :
  • SQL Server(Database)
  • IIS(Webserver)
  •  Windows Server(OS)

ARCHITECTURE OF .NET FRAMEWORK



INTEGRATED DEVELOPMENT ENVIRONMENT FOR C#

Microsoft provides the following development tools for C# programming:-
  • Visual Studio
  • Visual C# Express
  • Visual Web Developer
You can also write c# programs in notepad and compile them in Developer Comm
and Prompt which is again a part of the .Net Framework and comes automatically into your system when you install Visual Studio.



Wednesday, 25 October 2017

Introduction to Csharp

WHAT IS C#?


  • Basically, C# is an Object-oriented and Platform independent programming language developed by Microsoft as part of the .NET initiative. C# is pronounced as CSharp.
  • Anders Hejlsberg leads to the development of this language.
  • It is approved as a standard by ECMA(European Computer Manufacturers Association) and ISO(International Standard Organization ).

PREREQUISITES TO LEARN C# :

  • Basics of C and C++ programming languages is enough to learn C#. If you good knowledge of C and C++  then you will surely enjoy learning C#.

HISTORY OF C# :

  • During the development of  .NET, the libraries were originally written in a language called Simple Managed C (SMC) and later the language has been renamed as "CSharp".
  • CSharp's principle designer and lead architect Anders Hejlsberg has previously involved with the design of Visual J++, Borland Delphi and Turbo Pascal languages also. In interviews and technical papers he has started that flaws in most major programming languages like C++, JAVA, Delphi and SmallTalk drove the design of C# programming language.

DESIGN GOALS OF C# :

The ECMA standards listed the following design goals for Csharp,
  • It is intended to be a simple, modern, general-purpose and object-oriented programming language.
  • The language includes strong type checking, array bound checking, code portability and automatic memory management.
  • Programmer portability is very important in the software industry. So especially for those programmers already familiar with C and C++ languages  Csharp will be the best choice.
  • Support for Internationalization.
  • C# is suitable for writing applications for desktop, mobile, distributed, web and embedded systems.