Friday 17 June 2016

Basics Of C# (SEE SHARP)



ABOUT C# :

•It is pronounced as “see-sharp”. 
•It is a very useful programming language.
•It is a hybrid of c and c++.
•It was developed by Microsoft.
•C# is case sensitive.
•C# is an object-oriented programming language.

•It is used with web services on the .net platform and designed for improving productivity in the development of web applications.



FEATURES : 

•C# is elegant.
•It is a powerful object-oriented language.
•Secure. 
•Easy to learn and understand.
•Robust applications that run on the .net framework.
Linq and lambda expressions.
•Integration with windows.
•Properties and events.(Customization is easy)

•Use of standard library

WITH THE HELP OF C# :


WE CAN CREATE .


•Windows client applications.
•Distributed components.
•Client-server applications.
•Database applications.

•And many more...


REQUIREMENT (ENVIRONMENT SETUP) :

THE C# PROGRAM IS COMPILED BY TWO WAYS---
1- USING NOTEPAD (TEXT EDITOR)
2- VISUAL STUDIO (COMPILER)  

NOTE- I suggest you to download and install VISUAL STUDIO IDE (Integrated Development Environment) for compilation and execution of C# program ... click here to download.



STRUCTURE OF C# PROGRAM :



using System;
 namespace HackersRocks 
{
 class Display {
 static void Main(string[] args) {
 /* my first program in C# */ 
Console.WriteLine("Hackers Rocks");
 Console.ReadKey(); 
     }
  }
}


(Explain it latter)



*RUN ABOVE PROGRAM USING VISUAL STUDIO*


STEPS :-

1- Start Visual Studio.
2- On the menu bar, choose  File -> New -> Project.
3- Choose Visual C# from templates (lists), and then choose Windows.
4- Choose Console Application.(means cmd apps)
5- Specify a name for your project and click OK button.(give application name)
6-This creates a new project in Solution Explorer.(t is a kind of navigation bar)
7- Write code in the Code Editor.(copy and paste above code)
8- Click the Run button or press F5 key to execute the project.
9- A Command Prompt window appears that display a line "Hackers Rocks".
9-Enjoy.





*RUN ABOVE PROGRAM USING NOTEPAD*


STEPS :-

1- Open a text editor like notepad
2-  and write above code (copy and paste it).
*3- Save as the file as Anyname.cs (.cs is an extention)
4- Open the command prompt and go to the directory where you saved the file (by using cd command).
5- Type " csc Anyname.cs " and hit enter to compile your code.
(now your code is compiled)
6- If there are no errors in your code, the command prompt takes you to the next line 
( and it  generates Anyname.exe  an executable file.)
7-Type " Anyname "  to execute your program.
8- Now You can see the output Hackers Rocks printed on the cmd screen.




EXPLANATION OF THE ABOVE PROGRAM


using System :-  the using System is a  keyword which is used to include the System namespace in the program. A program generally has multiple using statements.

 namespace :- A namespace is a collection of classes. The HackersRocks namespace contains the class Display.
(Simply namespace is like the folder name and all the class XXX goes to namespace)

class declaration :-  the class HackersRocks contains the data and method definitions that your program uses. Classes generally contain multiple methods. Methods define the behavior of the class.
eg -  class class_name

Main method :- which is the entry point for all C# programs.

Connemts  (/*......*/ ) :- is ignored by the compiler and it is put to add comments in the program.It is used to increase readability of the program and also help to understand it.

Console.WriteLine() :- WriteLine() is a method of the Console class defined in the System namespace. This statement causes the message "HackersRocks" to be displayed on the screen.

Console.ReadKey() :-  ReadKey() is a method of the Console class, it is defined in the System namespace. This statement is used to take input from the user.
but here this statement is used  to hold cmd (Console) to wait for user input because cmd has hide itself after performing its operation or task.
 


BOOKS :


○ Head First C# - (By: Jennifer Greene, Andrew Stellman )

○ Adaptive Code via C#: Agile coding with design patterns and SOLID principles (Developer Reference) - (By: Gary McLean Hall )

○ The C# Player's Guide - (By: RB Whitaker )


No comments:

WINDOWS SUBSYSTEM FOR LINUX

Microsoft partnered with Canonical (creator of Ubuntu) to bring Linux environment experience in Windows 10. Through Windows Subsystem F...