473,386 Members | 1,708 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Namespaces and inheritance

Hi

I was just wondering - when you you use the using feature in C# to
reference a namespace in your project - does it enable you to write
classes that inherit from classes in the referenced namespace?

Thanks.

Nov 16 '05 #1
2 6382
The using statement is just to set up a shortcut so that you don't
necessarily have to type the fully qualified name for classes in your
code.

So, if you have class Test1 in namespace N1, you could do either of
these:

N1.Test1 a = new N1.Test1();
or
using N1
Test1 a = new Test1();

This assumes you have added a reference to the assembly defining
Namespace N1 to your project.
Sometimes you still have to use fully qualified names if you have name
collisions (e.g.:
using N1;
using N2;
//assume there is a Test1 in N1 and a different Test1 in N2, then you
still have to write
N1.Test1 a = new N1.Test1();

Now, back to your question,
the using statement does not impact the way you can write classes and
inherit classes, as far as I know.

So, assuming you have a class BaseClass in a namespace N1, and that you
have added a reference to the N1 assembly in your project, you can
'write' about that class either with or without the using statement:
without it:
N1.BaseClass b = new N1.BaseClass();
with it:
using N1;
BaseClass b = new BaseClass();

as far as inheriting from BaseClass, again, the using statement doesn't
affect the behavior. You may not be able to inherit from the base class
if it is sealed, but otherwise, you can do either of the following:

without using:
public class MySample : N1.BaseClass {...}
with using stmt:
using N1;
public class MySample : BaseClass {...}

Again, this assume you have added a reference to the N1 assembly in
your project.

HTH,
and I hope I'm not mistaken.

F.O.R.

Nov 16 '05 #2
Yes.
Either base class exists in referenced namespace or fully qualify namespace
before base class.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
SLODUG - Slovene Developer Users Group
www.rthand.com

"Karen" <ka********@campus.ie> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Hi

I was just wondering - when you you use the using feature in C# to
reference a namespace in your project - does it enable you to write
classes that inherit from classes in the referenced namespace?

Thanks.

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Steven Bethard | last post by:
In the "empty classes as c structs?" thread, we've been talking in some detail about my proposed "generic objects" PEP. Based on a number of suggestions, I'm thinking more and more that instead of...
8
by: Bernd Fuhrmann | last post by:
Hi! I just tried to write a little program, but GCC (Mingw 3.3.1) refused to compile it. So I'd like to know if there's something wrong with my code or if it is a bug in GCC. ---snip---...
2
by: Charlie | last post by:
Hi: If I have namespaces like "CompanyX.Data" and "CompanyX.Data.ClientTools". Does this mean that classes in ClientTools inherit classes in Data? Thanks, Charlie
11
by: Random | last post by:
I'm confused about the proper use and usefulness of namespaces. I beleive I understand the purpose is so the developer can put classes within namespaces to essentially organize your code. And I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.