BackThis is the first tutorial for learning csharp.Back


Well i suggest everyone to read:
What are the requirements for this Progrom .
Well we are no different from Computer "gurus", everyone has to start with a easy program to go. Well easy in the sense output is just a String output it can be "Hello user" or "welcome to csharpGoodies" etc. The main interest for you should be how the program starts, what are "main", "static", "return types", other classes inside the program and its properties and hows its different for C, C++ and java.
As everyone by now know C# is a simple, modern, object oriented, and type-safe programming language derived from C and C++. MicroSoft want this no different from basic c++ with more advanced features so the class you see is similar to C++ except for NameSpaces.

// First program in C#, Comments in program start with "//
using Csharpgoodies.Tutorial;{
using System;
class CsharpGoodies
{
public static void Main() {
Console.Write("Hello World!!The place to learn new technolgies --CsharpGoodies");
} //end of main
} // end of class CsharpGoodies
}//end of namespace

For C, C++ , Java Guru's and C# beginners:

I have taken care to give pin-point details of each and everything right in this first example. I request beginners to follow some of the links to get in detail with keywords, modifiers, namespaces and classes.

--1> “::” or “->” operators are not used in this canonical C# program. C# does not use either. If you see the keywords list provided you dont see "::", it is not an operator in C# at all, "->" is used in very few case we will discuss keywords in detail as we move on. Period "." is used in C# program as a separator in compound names such as Console.Write. example: class.method, namespace.namespaceChild.class.method


--2> Declaration Order is not significant

--3> Console: "Console" class can be written in any language. You dont see "#include" which you see in c++.  You dont even see header files

--4a> using Csharpgoodies.Tutorial;
well this is user defined namespace. As I develop some sample programs i will store under this namespace so that whenever i want to reference them it will be easy for me to do so. why .CsharpGoodies, Tutorial??? From years we follow this in Software industry whenever we write a high level namespace with company's name and then with children(sub namespaces .Tutorial) and grandchildren(might be classes, CsharpGoodies) etc.

 --4b> using System;
Please look at this carefully, you are referencing a "namespace". You are promting your program to use any classes(if) in the program with that of the namespace "System". what classes of "System" did we use in our "CsharpGoodies"? answer is Console. if you dont want to use namespace how can you reference the namespace, simply add whole namespace to all the classes you use example you can also say - System.Console.Write but if you have more classes of System to be referenced the neat and elegant way is to add a namespace using System;


--5> class classname {......}
As you all know how classes are written in C++ and java and structures in C. A class is a data structure that contains data members such as constants, fields, and events, function members such as methods, properties, indexers, operators, constructors, and destructors, and nested types.


--6> pubic .... Each member of a class has a form of accessibility. here it is "public", public members are available to all classes;

--7> static
In simple words, we can call this class without creating an instance of it. This is similar and familiar to java and c++ guys. I will deal with this hen i discuss "Modifiers".


--8> void Every method should have a return type. In our first example it is void but as we move further i will show you where return types are used.


--9> Main()
This is the method name, it has no arguments in this example but it can take arguments. This method return nothing as we indicated return type as void.


--10> Console.Write(" ")
Console is a class defined in the namespace System, and Write is a static method defined on that class. if you have not specified "using namespace" you can aslo do this by System.Console.Write. This prints out the String on to the console.


--11>Note: All statements end with a ";", semi-colon. Classes and methods begin with "{", and end with a "}", everything within these braces are called blocks and they have scope for program elements. All namespaces, classes and variables etc are case sensitive in C#.


--12> Tip of the tutorial:          "Practice makes man perfect."

Please email me the URL's if you happen to find resouces on csharp. mrweb24@hotmail.com

© 2000 Csharpgoodies  All rights reserved. Terms of Use.

 


Universal


 Bpath Network