In the article, I would brief about C#.net basic concepts. This would help to understand the object oriented concepts and help in the developing of services.
Let create a new console application. Open VS 2012 >New Projects > Visual C# > Windows> Console Application.
As you see, we have program class containing a static main method. This is entry point to the application. Let write Console.WriteLine and provide a meaningful sentence as shown and run the program using F5 and you can see the output in the console window.
Understanding simple data types, variables are best thought of as containers or buckets into which you put data. Below code shows example of string, int and Datetime Below example shows, how to take inputs from user and display it in console output window
Functions are the primary method of code organization and reuse in C#.Functions are groups of code that have a name, and can be called using parentheses. Below example shows function/method with void and return type.
Control flow is where the rubber really meets the road in programming. Without it, a program is simply a list of statements that are sequentially executed. With control flow, you can execute certain code blocks conditionally and/or repeatedly, these basic building blocks can be combined to create surprisingly sophisticated programs!
Conditional Statements: The “if”, “elseif,” and “else” statements are the most commonly used control flow statements.When you define a class, you define a blueprint for a data type. This does not actually define any data, but it does define what the class name means. That is, what an object of the class consists of and what operations can be performed on that object. Objects are instances of a class. The methods and variables that constitute a class are called members of the class.
Here is helper class, consists of private variables, a public method, class constructor and destructor as shown.
A class constructor is a special member function of a class that is executed whenever we create new objects of that class.A constructor has exactly the same name as that of class and it does not have any return type. A destructor is a special member function of a class that is executed whenever an object of its class goes out of scope. A destructor has exactly the same name as that of the class with a prefixed tilde (~) and it can neither return a value nor can it take any parameters. Destructor can be very useful for releasing memory resources before exiting the program. Destructors cannot be inherited or overloaded.
No comments:
Post a Comment
Note: only a member of this blog may post a comment.