Navigation Menu

Approach to C# Programming


What is C#?

C# is a server side programming language, which is developed by Microsoft.
C# gives the functionality of the application.

C# is a object oriented programming language which consists of classes and objects.


Environment Setup


Process to setup C# from Notepad. We can write C# programs using Notepad also. To be able to compile and run c# from notepad we have to set the following path from command line.






Enter the total path and enter csc to check c# compiler is added.




Writing a Basic C# Program

 Step1: Program in Notepad and save in specified folder to identify.


 Step2: Compile  the program


Step3: Run the program 




Variable Declaration
  • Variable is a memory pointer declared to store some value.
  • It can be any name given but should not exceed 32 charecters.
  • Should start with character only or underscore(_).

   Syntax: Datatype Variable_Name;



Defining a Class and Object

   Class is a blue print and logical representation of object.
  Object is a physical representation of class. Takes all the members from class.

   Syntax to define class:   Class Class_Name
                                         {
                                               // Class members
                                         }


   Syntax to define object: Class_Name object_name= new Class_Name();

   Program to specify usage of Class and Object.   



Conditional Statements

1.   if() statement:




2.   if...else() statement:




2.  Switch() statement:




Looping Statements

Looping statements are used to iterate a block of statements until a specified condition becomes true.

Looping statements are : for()while()dowhile()goto()

Iteration is an execution of block of statements for one time. When a sequence of instructions is executed in a repeated manner until condition becomes false, it is called a loop.

1.   for() loop:

 For statement is used whenever the number of iterations are fixed or known.

 Syntax: for(expression1;expression1;expression1)
             {
                       //block of statements
             }





2.   While() loop:

Syntax: While(Condition)
             {
                       //block of statements
             }






String Manipulation

   1. Reading and displaying a string

    





2. String Concatenation
  


   

3. Searching a String ( indexOf() function):
  




4. Substrings ( substr() ):

    Substring is a string function used to search and return a string based on index.

   Syntax: string.substr( Starting_position, No_of_charecters )

   


5. Comparing string ( Compare() ): 

   Compare() function is a static function compares two string and returns zero if equal.

  Syntax: String.Compare(“string1”,”string2”).

  Compares string2 with string1.




File Handling

  Example to Parse Menu

  Program:



  File Input Given




  Output



  Output Generated







0 comments: