Monday, 5 March 2018

021 C# Program Stucture

Program Stucture
You are going to write a simple program to get simple knowledge on C# program structure. To write a simple program we need to know about structure of  program. Here are the list of preliminary need to know before writing a simple program.

  •  namespace 
  •  method 
  •  function 
  •  comments multi line
  •  comments single line delete statement 
  •  class 
  •  main method

Below is a is the simple program of hello world. When you run this program, the program print the string "hello world" in the screen.

using System;
namespace student
{
         class student
         {
               public double Gatefees()
              {
                  double fees=300.65;
                  return fees;
             }
            static void main(string[] arg)
                  {
                      //Here is single line comments
                      /*Here is the exaple of 
                   multiline comments */
                   Console.WriteLine("hello world");
                }
      }
}
using system : system is a class at the root level. All other class of. Net comes under system class. System class is the namespace fundamental classes. The system namespace provides ,variable data type , like value type and reference type, event Handler, methods. using keyword tells the compiler, the component under system namespace will be available in this program. Generally a complex program have multiple using statement to include well namespace and functionality in it.

namespace student : namespace student keyword tells the compiler, class is declared under which namespace available only when this namespace is used. We have declared the class student, this will be available only, when a statement using student will be written at the top of the program. Namespace is a collection of classes, it can contain one or more classes. Here student is a namespace and student is the class under this namespace.

The next line is  a class declaration, a class is a template of an object. A class contain one or more method and variables. Here are student class accountant two method. The method, Gatefees will return the fees when it is called.

The main method is entry point of a program, when a program start running the main method is called fast.


Some points you should keep in mind
  •  C# is case sensitive 
  •  every C# statement ends with a semicolon 
  •  every C# program starts from A main method. 
  •  namespace must be included to get required component. The highest level of new namespace is system.

You have seen the hello world program,  now you will see how to create this program.

1) create project-->Empty project


2) a new project is created

3) add a c# source file ,Solution Explores-->Add-->New Item-- Code File-->> Name it student.cs

4)Write program in student.cs

5)Compile from built menu

6)Press F5

handling Syntax error : When a software engineer write program it is obvious that there will be some mistake on typing.. Net Framework is intelligent enough to report the error at the compile time. Engineer resolve the problem and compile again.. Net Framework is intelligence enough,it show possible resolution hints. Most of the time the hints works successfully and resolve the issue. But sometimes mislead the engineer in a wrong way.

C# keyword : Every language have some keyword to identify its features. This features active language structure. C# some keyword also. There are two type of Keyword reserve keyword and contextual keyword. Reserved keyword are the keywords that has been reserved by the C# own use. No variable, method, class can be declared with this name. Contextual keyword have some special meaning for some context, out of context this keyword can be used. Here is the list of some reserved keyword C#

Here is the list of reserved keyword by C#
 
 abstract  add  as  ascending
 async  await  base  bool
 break  by  byte  case
 catch  char  checked  class
 const  continue  decimal  default
 delegate  descending  do  double
 dynamic  else  enum  equals
 explicit  extern  false  finally
 fixed  float  for  foreach
 from  get  global goto
group  if  implicit  in
 int  interface  internal  into
 is  join  let  lock
 long  namespace  new  null
 object  on  operator  orderby
 out  override  params  partial
 private  protected  public  readonly
 ref  remove  return  sbyte
 sealed  select  set  short
 sizeof  stackalloc  static  string
 struct  switch  this  throw
 true  try  typeof  uint
 ulong  unchecked  unsafe  ushort
 using  value  var  virtual
 void  volatile  where  while
 yield




 Here is Some of contextual keyword by C#
  • add    
  • alias    
  • ascending
  • async    
  • await    
  • descending
  • dynamic    
  • from    
  • get






















No comments:

Post a Comment

বাঙালির বেড়ানো সেরা চারটি ঠিকানা

  বাঙালি মানে ঘোড়া পাগল | দু একদিন ছুটি পেলো মানে বাঙালি চলল ঘুরতে | সে সমুদ্রই হোক , পাহাড়ি হোক বা নদী হোক। বাঙালির ...