C# Newbie Question

  • Thread starter Thread starter Siva
  • Start date Start date
S

Siva

Hi:

I have a basic question:
For example, consider the following statement in C#:
using System.IO;

The above statement gets the metadata for types defined
in the IO namespace.
By default, C# compiler only looks into mscorlib.dll.
Does that mscorlib.dll have the reference to IO.dll
implicitly?

The reason I am asking this for using the following
namespace:
System.Data.OracleClient, I need to add a reference
explicitly to my C# program on VS.Net

Is there a way I can look at ILDASM for an assembly &
know what dlls are referenced?

Any help appreciated.

Thanks,
Siva
 
Siva,

See inline.

Siva said:
Hi:

I have a basic question:
For example, consider the following statement in C#:
using System.IO;

The above statement gets the metadata for types defined
in the IO namespace.

Actually, it does not. It only serves to tell the compiler to allow
types in that namespace to be declared without using the full name. It's a
shorthand of sorts. If you didn't place that there, and you wanted to
declare a Stream instance, you would have to do:

// Declare a stream.
System.IO.Stream pobjStream;

Everywhere you wanted to use it.
By default, C# compiler only looks into mscorlib.dll.
Does that mscorlib.dll have the reference to IO.dll
implicitly?

The compiler will always look to mscorlib.dll. I think it always looks
at System.dll as well (I am not sure about this). If you want other
references, you have to tell the compiler to use them.
The reason I am asking this for using the following
namespace:
System.Data.OracleClient, I need to add a reference
explicitly to my C# program on VS.Net

Is there a way I can look at ILDASM for an assembly &
know what dlls are referenced?

You should only have to set a reference to System.Data.OracleClient.dll
in order to use the classes from that namespace. Generally speaking though,
if you use ILDASM on any assembly, it will show you what other assemblies
are referenced (or another tool, like Reflector or Anakrino).

However, it should be noted that there might be some legal restrictions
on decompiling or disassembling assemblies (for example, Microsoft has an
EULA).

Hope this helps.
 
Siva said:
I have a basic question:
For example, consider the following statement in C#:
using System.IO;

The above statement gets the metadata for types defined
in the IO namespace.

I don't think I'd express it like that - it just means that when a type
name needs to be qualified, one of the namespaces it will check is
System.IO.
By default, C# compiler only looks into mscorlib.dll.

Well, that depends on how you invoke it - but usually from the command
line it looks in a bunch of places, and from VS.NET most projects will
be set up with a number of assembly reference too.
Does that mscorlib.dll have the reference to IO.dll
implicitly?

There *is* no IO.dll - there System.IO classes are within System.dll
and mscorlib.dll.
The reason I am asking this for using the following
namespace:
System.Data.OracleClient, I need to add a reference
explicitly to my C# program on VS.Net

Is there a way I can look at ILDASM for an assembly &
know what dlls are referenced?

I think you may be getting a bit confused between namespaces and
assemblies - one assembly can contain multiple namespaces, and multiple
assemblies can each contribute a type to the namespace.

The right way to go here is to look at the documentation for the types
you're using. For instance, looking at the OracleCommand class, the
documentation has nearly the bottom:

Assembly: System.Data.Oracleclient (in System.Data.Oracleclient.dll)

So you need to find System.Data.Oracleclient.dll, and add a reference
to that in VS.NET. On my box at least, the DLL is in
c:\Windows\Microsoft.NET\Framework\v1.1.4322
 
Thanks Nicholas.

That was clear about the "using" statement.

Siva
-----Original Message-----
Siva,

See inline.

Hi:

I have a basic question:
For example, consider the following statement in C#:
using System.IO;

The above statement gets the metadata for types defined
in the IO namespace.

Actually, it does not. It only serves to tell the compiler to allow
types in that namespace to be declared without using the full name. It's a
shorthand of sorts. If you didn't place that there, and you wanted to
declare a Stream instance, you would have to do:

// Declare a stream.
System.IO.Stream pobjStream;

Everywhere you wanted to use it.
By default, C# compiler only looks into mscorlib.dll.
Does that mscorlib.dll have the reference to IO.dll
implicitly?

The compiler will always look to mscorlib.dll. I think it always looks
at System.dll as well (I am not sure about this). If you want other
references, you have to tell the compiler to use them.
The reason I am asking this for using the following
namespace:
System.Data.OracleClient, I need to add a reference
explicitly to my C# program on VS.Net

Is there a way I can look at ILDASM for an assembly &
know what dlls are referenced?

You should only have to set a reference to System.Data.OracleClient.dll
in order to use the classes from that namespace. Generally speaking though,
if you use ILDASM on any assembly, it will show you what other assemblies
are referenced (or another tool, like Reflector or Anakrino).

However, it should be noted that there might be some legal restrictions
on decompiling or disassembling assemblies (for example, Microsoft has an
EULA).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
Any help appreciated.

Thanks,
Siva


.
 
Thanks Nicholas.

That was clear about the "using" statement.

Siva
-----Original Message-----
Siva,

See inline.

Hi:

I have a basic question:
For example, consider the following statement in C#:
using System.IO;

The above statement gets the metadata for types defined
in the IO namespace.

Actually, it does not. It only serves to tell the compiler to allow
types in that namespace to be declared without using the full name. It's a
shorthand of sorts. If you didn't place that there, and you wanted to
declare a Stream instance, you would have to do:

// Declare a stream.
System.IO.Stream pobjStream;

Everywhere you wanted to use it.
By default, C# compiler only looks into mscorlib.dll.
Does that mscorlib.dll have the reference to IO.dll
implicitly?

The compiler will always look to mscorlib.dll. I think it always looks
at System.dll as well (I am not sure about this). If you want other
references, you have to tell the compiler to use them.
The reason I am asking this for using the following
namespace:
System.Data.OracleClient, I need to add a reference
explicitly to my C# program on VS.Net

Is there a way I can look at ILDASM for an assembly &
know what dlls are referenced?

You should only have to set a reference to System.Data.OracleClient.dll
in order to use the classes from that namespace. Generally speaking though,
if you use ILDASM on any assembly, it will show you what other assemblies
are referenced (or another tool, like Reflector or Anakrino).

However, it should be noted that there might be some legal restrictions
on decompiling or disassembling assemblies (for example, Microsoft has an
EULA).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
Any help appreciated.

Thanks,
Siva


.
 
See my questions inline.
Siva
-----Original Message-----


I don't think I'd express it like that - it just means that when a type
name needs to be qualified, one of the namespaces it will check is
System.IO.
[Siva]:"when a type name needs to be qualified" - what
does this mean?
Well, that depends on how you invoke it - but usually from the command
line it looks in a bunch of places, and from VS.NET most projects will
be set up with a number of assembly reference too.
[Siva]: Suppose i invoke from command line, what are the
bunch of places it looks for?
There *is* no IO.dll - there System.IO classes are within System.dll
and mscorlib.dll.
[Siva]: So System.IO classes are within System.dll or
mscorlib.dll or both?
I think you may be getting a bit confused between namespaces and
assemblies - one assembly can contain multiple namespaces, and multiple
assemblies can each contribute a type to the namespace.

The right way to go here is to look at the documentation for the types
you're using. For instance, looking at the OracleCommand class, the
documentation has nearly the bottom:

Assembly: System.Data.Oracleclient (in System.Data.Oracleclient.dll)

So you need to find System.Data.Oracleclient.dll, and add a reference
to that in VS.NET. On my box at least, the DLL is in
c:\Windows\Microsoft.NET\Framework\v1.1.4322
[Siva]: Thanks for answering my questions!!
 
[Siva]:"when a type name needs to be qualified" - what
does this mean?

It means when your code contains an unqualified type name such as Form,
or StreamReader. If you use fully qualified names throughout your code
(System.Windows.Forms.Form, System.IO.StreamReader) you don't need
using statements like using System.IO; at all.
Well, that depends on how you invoke it - but usually from the command
line it looks in a bunch of places, and from VS.NET most projects will
be set up with a number of assembly reference too.
[Siva]: Suppose i invoke from command line, what are the
bunch of places it looks for?

If you have a look at csc.rsp (in the same directory as csc.exe) you
can see the options that are used by default.
within System.dll and mscorlib.dll.
[Siva]: So System.IO classes are within System.dll or
mscorlib.dll or both?

Both.
 
Back
Top