Why isn't 'using System' sufficient to write all the programs in c#? Why do i need to add different namespaces according to my requirement? For example if i want to use xmlelement I need to use system.xml namespace. Isn't system.xml a part of system namespace? If yes, then why do I need to mention 'using System.xml' along with 'using System;?
C#
Hi

VulpesRank #55 · 29.2K reputationPosted Sep 16, 2013, 7:59 AM EDT
However, for the purposes of C#'s 'using' directive, each namespace is treated separately. So, if you want to use a class in the System.Xml namespace (XmlDocument say) without having to 'fully qualify' its name, then you must use:
using System.Xml;
You might reasonably have thought that if you did this:
using System;
then you'd be able to do this:
Xml.XmlDocument doc = new Xml.Document();
but, if you try to do that, you'll get a compiler error.
Curiously, though, you can do this sort of thing in VB.NET which is a much more forgiving language than C#. For example the following compiles fine:
Suthish NairRank #92 · 22.8K reputationPosted Sep 15, 2013, 11:43 AM EDT
Pavan RamamurthyRank #1,682 · 906 reputationPosted Sep 15, 2013, 9:54 PM EDT
Jignesh TrivediRank #16 · 50.3K reputationPosted Sep 15, 2013, 10:43 PM EDT
system and system.xml both are different namespace. it might possible different namespace with in different assembly or two namespace contain same class.
hope this will help you.
vidya3 reputationPosted Sep 25, 2013, 9:03 PM EDT