Writing 1st program of C#
Rules to be followed.
Avoid complex coding in your program if you have complex program then use your time to analysis and divide into subtasks.
2. Be consistent
Be consistent as much as possible whatever you do. This is especially important when writing your code against your coding rules-coding standards.
3. Have a coding standard
A coding standard defines how you write your code.
1. For class names use Pascal Casing
2. For Function names use Pascal Casing
3. For Properties use Pascal Casing
4. Use camel Casing for member variables, parameters,
local variables
5. To distinguish between local and member variables use
this keyword and don’t use
Hungarian and notations
having _,m_,s_ for your local or member variables
1.
Comment and document your code
You use comments in C#
via // or /**/. Why not to go a step ahead and use /// also.
Visual Studio and Sharp Develop environments can comment on your
methods and classes using /// notation. Before your method enter / for 3 times
and add additional comment info
5. Test your code
Use some unit testing tools using visual studio and test the source code.
Coding Standard Notations
There are several notations to follow for names and here they are.
Hungarian Notation: Prefix the type of value
for a variable name.
Ex: intAge,strName...etc
Camel casing Notation: first letter lower and
next each word has capital letter.
Ex: lastName,firstName,foreName,surName
PascalCasing Notation: every word first letter
capital letter
Ex: FirstName,LastName,ForeName,SurName
Snake Notation: each word is in lower
case, and separated by underscore.
Ex: last_name,first_name,fore_name,sur_name
Saving the C# code in
Notepad
Here are the steps.
1.
Open the new notepad with shortcut keys Ctrl+N or directly from
Windows search box.
2.
We should write the C# code or program.
3.
We can save the program at a particular file location with extension “.cs”
4.
Save the program with Ctrl+S or via file menu.
Example
Compiling C# Programs
thru Developer Command Prompt
Step 1: Open the text editor like
Notepad or Notepad++, and write the code that you want to execute. Now save the
file with .cs extension
Step 2: Compiler your C# source code with the use of CSC command like below
Ex: CSC<filename>.cs
If your program has no error, then it will create a filename.exe file in the same directory where you have saved your program. Suppose you saved the above program as demo.cs. So, you will write csc demo.cs on cmd. This will create a demo.exe file.
Executing compiled code thru
Developer Command Prompt
Comments
Post a Comment