Namespace in C#.
Namespaces group related classes and types, and they define categories in which we can include any new class that provides related functionality.
Namespaces group related classes and types, and they define categories in which we can include any new class that provides related functionality.
namespace MyCompany.r4r
{
class MyClass
{
// some code here
}
}
namespace MyCompany.r4r
{
class MyClass1
{
// some code here
}
} |
{ class-body } For Example.
the stack. Objects, however, are reference types, and are created on the heap, using the keyword new, as in the following:
t does not actually contain the value for the test class object; it contains the address of that (unnamed) object that is created on the heap. t itself is just a reference to that object. How to create a program in C#? Step 1: Start notepad from Start -> Program Files -> Accessories -> Notepad so that you can write the HelloWorld program. The program you write in C# is also called as source code. Step 2: Write the HelloWorld program, you can either type the program shown below into notepad or just copy-paste it from here-
Step 3: Once you have finished typing your program you should Save the source code file. In fact after making any changes to your source code, you should always save the file. To save the file for the first time in notepad click on File menu -> Save As. In the Save As dialog select the directory from the Save In dropdown where you want to save your files, I generally save my files to C:\csharp, and then in the File name textbox, enter the file name as HelloWorld.cs (although you can provide any name you want but it should have an extension.cs). and click Save. Once you have saved the source code, and if you make any further modifications, in notepad use the Ctrl+S keyboard short-cut to save your source code file. Step 4: Since you have finished writing the source code its time to compile it. Since we are using a command-line compiler that ships with the .NET SDK, start the command prompt from Start -> Program Files -> Accessories -> Command Prompt. Or go to Start -> Run, type cmd and press enter. Now from the command prompt navigate to the directory where you have stored the source code file by issuing the following DOS commands.cd\ -To navigate to the root of the derived csharp - To navigate to the csharp directory. Once you are in the csharp directory where you saved the source code file earlier, its time to run the C# Compiler csc.exe. Issue the following command to compile our HelloWorld.cs program:csc HelloWorld.cs Step 5: If the compilation of the source code was successful then a new executable (Exe) file by the name HelloWorld.exe will be created in the directory you compiled the source code. To execute the program simply type the name of the executable file at the command prompt. Points to Remember resides in the C:\windows\Microsoft. NET\Framework\v1.0.4322 directory. |
No comments:
Post a Comment