C++ language suffer from a criticism that
it was not fully object oriented because as par the rules of OOP programming
every line of cod should be defined inside the class only but main function in
C++ program will always be outside the class.
NOTE- while design C++ the designers could not place Main inside
the class because if Main is inside the class it can execute only when called
by using object of the class in which it was present, whereas object is getting
created main function only. (Circular dependency)
When the java language were designed the designers are given a permanent solution to the problem of main by introducing “static method(function)”, which can execute without the object of class. So if the main method is declared as static inside the class it can become the entry point of the program where the object of the class created and rest of the members in the class can execute as following.
C#/JAVA Program
Class example
{
Collection of member
Static void Main (
) ß entry point
{
Create the object invoke
Member of class
}
}
While designing C# the developers of the
language has followed the same guideline prescribed by java in case of Main so in C# also Main method gets defined with in the
class as Static and the program structure looks exactly same as the java
programs structure we have seen above.
Suppose if your class contain only main method
in it to execute the class we don’t reqired to create object of the class for
execution.
THE SOFTWARE REQUIREMENT, THE HARDWARE REQUIREMENT AND THE WEBSITE FOR
c#.NET.
Hardware requirement-
- Windows XP with server pack 3 or windows vista (home premium business) or windows 7.
- Visual Studio .Net 2010 or 2008.
- Oracle DB 11g or SQL server 2008 or 2005.
- MS office.
Books – C#3.0 unleashed
(SAMS)
C# 2008 developers (SAMS)
Professional C# 2008 (work press).
Website-
Syntax to define a class in C#;-
[<modifiers>]class<name>
{
-stmts
}
|
- Modifiers or few optional keywords like public, private, static etc. which can be used on a cclass.
- C# is a case sensitive language so in case of casing it adopts few conventions—
- All keywords will be
in lower case only.
- All library function
must be used in proper case only i.e. class name, Method name etc.
(WriteLine) – Proper
case
Syntax of Main Method:-
static void/int
{
- stmts
}
|
- As discussed earlier must and should name should be declared as static if we want the execution to start from there.
- Main can be either a non value returning
method and can also return a value of type int only.
- Main method can tack parameters also but only of type string [] array.
Writing a First Program:-
- to write a program in any .net language wee can use of any editor like Visual Studio or noted etc.
- developing a program in notepad
- Open the notepad and write following code in it.
class Example
{
int x = 100;
static void
{
System.Console.WriteLine("First c# program");
}
}
|
4 . Now save the program in a desire location as Example.cs
Note- a C# program should
use an extension of .cs and the VB program should use an extension of .vb
5. Compiling the program – to compile a C# program we
required a C# compiler, which comes along with the visual studio software. It
is a command line tool which has to be used from Visual; Studio command prompt.
To use it –
Go to start menu à program à MS visual studio à visual studio tools à visual studio command
prompt, click on it to open.
Now move into the folder ware your program has been saved. And used the C# compiler as following. And used the C sharp compiler as following
C:\......................................\vc>cd\
C:\>cd csharp4
C:\csharp4>csc Example.cs
If the program is
compiled successfully without any error it creates a file Example.exe , which
contains IL code in it.
6. Executing the program- Now from the command prompt run your
exe file as following –
C:\csharp4>Example
ildasm : (intermediate language disassembly )-->
It is a tool that can be used
for viewing that contained of the exe file generated after compilation which
contains IL code in it.
It can be used from visual studio command
prompt as following
C:\csharp4>ildasm Example.exe
No comments:
Post a Comment