.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> C# >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Namespace using C#.net

Posted By:Narayanan       Posted Date: August 21, 2012    Points: 200    Category: C#    URL: http://www.dotnetspark.com  

In this Article , I will explain create and call namespace using C#.net in the Application. First of all , we should know Namespace and it usage.
 

Namespace:
  Namespace is a Collection of classes.
  Implementing Namespaces in your own code is a good habit because it is likely to save you from problems later when you want to reuse some of your code.
  user can create more than 1 class files and user can create enum within class file.
Use of Namespace:
  Namespaces allow you to create a system to organize your code.
Syntax of Namespace:
  namespace <namespace_name>
  class <class_name>
  Method <method_name> 
  For Eg:
using System;
namespace Test_namespace
{
    class cls_namespace
    {
        public static void messageDisplay()
        {
            System.Windows.Forms.MessageBox.Show("Create Namespace");
        }
    }
}
In this Example, we create a namespace that is called Test_namespace,we add class in the namespace that is called cls_namespace and we create method in the Class that is called messageDisplay.
How to call the Namespace in the C#.net?
First ,we create an Application in the VS 2008.
we just add a Code file in the Project and name is called "Test_namespace".
Copy code and paste into Code File.
using System;
namespace Test_namespace
{
    class cls_namespace
    {
        public static void messageDisplay()
        {
            System.Windows.Forms.MessageBox.Show("Create Namespace");
        }
    }
}
just use "Using" Keyword for declare namespace in the Parent
Open Project Code view
call a Namespace in the Code View.
using Test_namespace;
call a Method in the Load Event.
Copy code and paste into Code view.
  cls_namespace.messageDisplay();
Run the Application . User can see the MessageBox before form loading

 Subscribe to Articles

     

Further Readings:

Responses
Author: Ravi Ranjan Kumar         Company URL: http://www.dotnetspark.com
Posted Date: August 31, 2012

hi Narayn first of all check your Codes format, its not appropriate and better use these short piece of code for CodeSnippets.

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend