Skip to main content

How To Organize Classes Using Namespaces by #RathrolaPremKumar

Today, in this article, we shall see what does namespace actually do and how to organize the classes using namespaces.




At the end of this article, we will have learned the below bullet points.
  1. Introduction
  2. Two-Tiered NameSpaces
  3. Commonly used namespaces in .NET Framework.
  4. Examples
Let’s begin.
Introduction
We use namespaces to organize classes into a logically related hierarchy. Namespaces function as both, an internal system for organizing our application and an external way to avoid name collision between source code and application.
Because more than one companies may create a class with the same name, such as Employee, when we create code, that may be seen or used by third parties. It’s highly recommended that we shall organize our classes by using a hierarchy of namespaces. By practising this, we can avoid interoperability issues on application.
To create a namespace, we simply type a keyword namespace followed by the name. It is recommended to use Pascal case for namespaces.
It is also recommended that you create at least two-tiered namespaces, which is one that contains two levels of classification, separated by a period.
Let us see sample example of a two-tiered namespace.
  1. namespace Infosys.Sales {  
  2.     //define your classes within the namespace  
  3.     public class customer() {}  
  4. }   
Above two-tiered namespace declaration is identical to writing each namespace in nested format, as shown in the following code. 
  1. namespace CompanyName {  
  2.     namespace Sales {  
  3.         public class Customer() {}  
  4.     }  
  5. }   
In both cases, we refer to class by using the following code.
  1. CompanyName.Sales.Customer();   
Note
We should avoid creating a class with same name as namespace.
Commonly used namespaces in .NET Framework
Microsoft .NET Framework is made of many namespaces, the most important one being System. The System namespace contains classes that most of the applications use to interact with operating system.
For example, the system namespace contains the console class which provides several methods, including WriteLine, which is a command that enables us to write code to an on-screen console.
We can access WriteLine method of console as follows.
  1. System.Console.WriteLine("Prem Kumar Rathrola");   
A few of other namespaces that are provided by .NET Framework through the system namespace are listed below.

  • System.Windows.Forms
    Provides the classes that are useful for building applications based on windows.

  • System.IO
    Provides classes for reading and writing data to files
  • System.Data
    Provides classes that are useful for data access
  • System.Web
    Provides classes that are useful for building web forms applications

Comments

Popular posts from this blog

ERROR: Cannot resolve the collation conflict between SQL_Latin1_General_CP1_CI_AS and Latin1_General_CI_AS_KS_WS in the equal to operation

ERROR: Cannot resolve the collation conflict between SQL_Latin1_General_CP1_CI_AS and Latin1_General_CI_AS_KS_WS in the equal to operation
dont get panic if u get the following error while in your joinings, there is a simple way to solve this.
it is because of collation settings on two columns we are doing joinings. it is because of collation settings on two columns we are doing joinings
First step is to figure out what are two colaltion that cause for conflicts. Let us assume that collation has not been set at the column level and instead at db level, then we have to execute two simple statements as below.

Statements: Select DATABASEPROPERTYYEX('DB1',N'Collation') Select DATABASEPROPERTYYEX('DB2',N'Collation')
One more thing, make a note that if you are on sharepoint you will get error as below
Latin_General_CI_AS_KS_WS. if you are on most any other database and use the dafault settings you may get this SQL_Latin_General_CP1_CI_AS.
Now we have to do some…

How To Create The Data Adapter Object Using ADO.NET by #RathrolaPremKumar

By reading this article, you will learn key points in ADO.NET, as given below. What is Data Adapter?Primary Data Adapters for the databases.Data Adapter properties.Methods used by Data Adapter.How to create Data Adapter with an example? Let’s start our demo with a Data Adapter introduction. Actually, we use Data Adapter object to establish the connection to the data source and manage the movement of date to and from the database. What is Data Adapter? A data adapter aobject serves as a bridge between a data set object and Data Source such as a database to retrieve and save the data. Data adapter contains a set of database commands and a database connection, which we use to fill a dataset object and update the Data Source. Primary data adapters for databases? .NET makes two primary data adapters available for use with the databases. Other data adapters can also be integrated with Visual Studio .NET. Primary Data Adapters are mentioned below. OleDbData Adapter, which is suitable for use wi…

'#Resolve' To export a list, you must have a Microsoft SharePoint Foundation-compatible application.

Searching this error message easily finds the root of the problem. There is a problem with the Office 64 bit version. It doesn’t work with SharePoint. These solutions generally tell you to uninstall your 64 bit office and install a 32 bit version. Happily there is a much easier solution.
Despite the error message the export actually works! Notice the yellow bar at the bottom of your browser. Simply save the .iqy file normally and open it with Excel. It’s that simple. The error message is certainly a nuisance but does not actually stop the export.
Thanks for ready my blog :)