Monday, October 15, 2012

First Code in C# to Get Prepared for API programming:

In the program.cs box, there are some existing lines of code. The first group of lines is showing the .Net toolkits that your program is using. Let’s just assume that they are needed for the coding part for now. We will talk about them later in detail. 

I will introduce namespace and class as a grouping tool that is used to group your code for now and later we will talk about them more. Main is the first method (and the only method here in this code right now) of your class. The specific thing about main is that the debugger starts your code from the first line of Main function and proceeds line by line. Main name is reserved by the program and you cannot name other methods in your code as main.

In the following you will see some lines of codes that clarify the definitions of data types, operator, method, and control structures.



In this step you will learn how to define variables, define their type, and assign a value to them. Then you will see how to use operators to do some actions on your variables. In the following code, the “numMoCredits” and “numMarkCredits” are your symbols or variables. The type of these variables is defined as integer using “int” before them. Console.writeline and console.write help you to print out the result on the computer display (historically called a console).

Step 2:

In this step you will learn how to use a method or function to do the same process as the previous step. The function name is “caculateSum” and it does not get any parameters and does not return any values. The Main() function invokes the calculateSum() function.

The result would be the same as the previous code.


Step 3:

In this step a function that accepts two integer variables as input parameters is added to the code. Have a look to the result window and see how it has been changed.


Step 4:

In this step a method that accepts two integer values and two string values as inputs has been added to the previous codes.


In this new code, a function is defined in a way that accepts two input values and returns an integer as an output.


This is the last step of this post. In this step, it is asked from the user to enter two names. Then the program prints out those two names and provides the sum of the credits of those two students.

Here is the link to a video on Introduction to the C# Programming Language on MSDN website. Please watch the video and try to do the same thing and submit the executive file to eLearning.

No comments:

Post a Comment