Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

C# Example

I found the code sample below on the microsoft web site that allows you to
create a simple TCP listener with c#:
http://msdn.microsoft.com/library/default.asp?URL=/library/techart/PDC_websv
c.htm

But when I compile I get this error:

Server.cs(2,14): error CS0234: The type or namespace name 'Net' does not
exist i
n the class or namespace 'System'
Server.cs(3,14): error CS0234: The type or namespace name 'Net' does not
exist i
n the class or namespace 'System'

Is there something I'm not doing right? How do I get the Net classes? (Did
they not come with the NGWS preview)?

Thanks,
Greg

/* Begin Code */
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;

class Server
{
public static void Main()
{
DateTime now;
String strDateLine;
Encoding ASCII = Encoding.ASCII;

// listen on port 23
TCPListener tcpl = new TCPListener(23);

tcpl.Start();

Console.WriteLine("Waiting for clients to connect");
Console.WriteLine("Press Ctrl+c to Quit...");

while (true)
{
// Accept will block until someone connects
Socket s = tcpl.Accept();

// Get the current date and time then concatenate it
// into a string
now = DateTime.Now;
strDateLine = now.ToShortDateString() + " " +
now.ToLongTimeString();

// Convert the string to a Byte Array & send it
Byte[] byteDateLine =
ASCII.GetBytes(strDateLine.ToCharArray());
s.Send(byteDateLine, byteDateLine.Length, 0);
Console.WriteLine("Sent " + strDateLine);
}
}
}

/* End Code */
[1739 byte] By [Greg Huber] at [2007-11-9 18:21:33]
# 1 Re: C# Example
Hi Greg,
Just compile with system.net.dll.

For example:
csc /target:winexe
/r:system.dll,system.winforms.dll,system.drawing.dll,system.net.dll,microsof
t.win32.interop.dll yourfile.cs

- Marcus

"Greg Huber" <ghuber@NOSPAMPLEASEhcr-manorcare.com> wrote in message
news:3997e97a$1@news.dev-archive.com...
> I found the code sample below on the microsoft web site that allows you to
> create a simple TCP listener with c#:
>
http://msdn.microsoft.com/library/default.asp?URL=/library/techart/PDC_websv
> c.htm
>
> But when I compile I get this error:
>
> Server.cs(2,14): error CS0234: The type or namespace name 'Net' does not
> exist i
> n the class or namespace 'System'
Marcus E at 2007-11-11 22:29:14 >
# 2 Re: C# Example
Thanks Marcus, that worked!

Greg

"Marcus E" <no@mail.com> wrote in message news:3997f38e@news.dev-archive.com...
> Hi Greg,
> Just compile with system.net.dll.
>
> For example:
> csc /target:winexe
>
/r:system.dll,system.winforms.dll,system.drawing.dll,system.net.dll,microsof
> t.win32.interop.dll yourfile.cs
>
> - Marcus
>
> "Greg Huber" <ghuber@NOSPAMPLEASEhcr-manorcare.com> wrote in message
> news:3997e97a$1@news.dev-archive.com...
> > I found the code sample below on the microsoft web site that allows you
to
> > create a simple TCP listener with c#:
> >
>
http://msdn.microsoft.com/library/default.asp?URL=/library/techart/PDC_websv
> > c.htm
> >
> > But when I compile I get this error:
> >
> > Server.cs(2,14): error CS0234: The type or namespace name 'Net' does not
> > exist i
> > n the class or namespace 'System'
>
>
>
Greg Huber at 2007-11-11 22:30:19 >
# 3 Re: C# Example
You'll notice that a lot of people have been having problems with
compilations, especially on examples. I posted a similar problem with XML,
but the revelation hit me a couple of hours later. When you're compiling an
example, check out the listing in the reference. Someone who knows a little
more about assemblies than me could add some detail here, but the name of
the dll you need to include will be listed in the Requirements section of
the class members. For example, if you grab one of the classes under
System.Net, you'll see System.net.dll listed as the required assembly.

Alternatively, you can do like I did the first time: Go to %system
root%/ComPlus/v2000.14.1812, and start including relavent looking dlls until
it compiles :)

"Greg Huber" <ghuber@NOSPAMPLEASEhcr-manorcare.com> wrote in message
news:3997e97a$1@news.dev-archive.com...
> I found the code sample below on the microsoft web site that allows you to
> create a simple TCP listener with c#:
>
http://msdn.microsoft.com/library/default.asp?URL=/library/techart/PDC_websv
> c.htm
>
> But when I compile I get this error:
>
> Server.cs(2,14): error CS0234: The type or namespace name 'Net' does not
> exist i
> n the class or namespace 'System'
> Server.cs(3,14): error CS0234: The type or namespace name 'Net' does not
> exist i
> n the class or namespace 'System'
>
> Is there something I'm not doing right? How do I get the Net classes? (Did
> they not come with the NGWS preview)?
>
> Thanks,
> Greg
>
> /* Begin Code */
> using System;
> using System.Net;
> using System.Net.Sockets;
> using System.Text;
>
> class Server
> {
> public static void Main()
> {
> DateTime now;
> String strDateLine;
> Encoding ASCII = Encoding.ASCII;
>
> // listen on port 23
> TCPListener tcpl = new TCPListener(23);
>
> tcpl.Start();
>
> Console.WriteLine("Waiting for clients to connect");
> Console.WriteLine("Press Ctrl+c to Quit...");
>
> while (true)
> {
> // Accept will block until someone connects
> Socket s = tcpl.Accept();
>
> // Get the current date and time then concatenate it
> // into a string
> now = DateTime.Now;
> strDateLine = now.ToShortDateString() + " " +
> now.ToLongTimeString();
>
> // Convert the string to a Byte Array & send it
> Byte[] byteDateLine =
> ASCII.GetBytes(strDateLine.ToCharArray());
> s.Send(byteDateLine, byteDateLine.Length, 0);
> Console.WriteLine("Sent " + strDateLine);
> }
> }
> }
>
> /* End Code */
>
>
>
>
Oscar at 2007-11-11 22:31:23 >
# 4 Re: C# Example
Yeah, playing around always seems to be the best way to figure it out! I'll
agree on that one :) I wonder what harm is done including extra namespaces
when you don't need them, maybe just a bigger EXE? (ie, similar to C++).
I'll have to dig up the documentation on the reference that you're
mentioning so I don't have to be lazy.

Thanks for the advice!

Greg

"Oscar" <consulBanana@hotmail.com> wrote in message
news:39982ac4$1@news.dev-archive.com...
> You'll notice that a lot of people have been having problems with
> compilations, especially on examples. I posted a similar problem with
XML,
> but the revelation hit me a couple of hours later. When you're compiling
an
> example, check out the listing in the reference. Someone who knows a
little
> more about assemblies than me could add some detail here, but the name of
> the dll you need to include will be listed in the Requirements section of
> the class members. For example, if you grab one of the classes under
> System.Net, you'll see System.net.dll listed as the required assembly.
>
> Alternatively, you can do like I did the first time: Go to %system
> root%/ComPlus/v2000.14.1812, and start including relavent looking dlls
until
> it compiles :)
>
> "Greg Huber" <ghuber@NOSPAMPLEASEhcr-manorcare.com> wrote in message
> news:3997e97a$1@news.dev-archive.com...
> > I found the code sample below on the microsoft web site that allows you
to
> > create a simple TCP listener with c#:
> >
>
http://msdn.microsoft.com/library/default.asp?URL=/library/techart/PDC_websv
> > c.htm
> >
> > But when I compile I get this error:
> >
> > Server.cs(2,14): error CS0234: The type or namespace name 'Net' does not
> > exist i
> > n the class or namespace 'System'
> > Server.cs(3,14): error CS0234: The type or namespace name 'Net' does not
> > exist i
> > n the class or namespace 'System'
> >
> > Is there something I'm not doing right? How do I get the Net classes?
(Did
> > they not come with the NGWS preview)?
> >
> > Thanks,
> > Greg
> >
> > /* Begin Code */
> > using System;
> > using System.Net;
> > using System.Net.Sockets;
> > using System.Text;
> >
> > class Server
> > {
> > public static void Main()
> > {
> > DateTime now;
> > String strDateLine;
> > Encoding ASCII = Encoding.ASCII;
> >
> > // listen on port 23
> > TCPListener tcpl = new TCPListener(23);
> >
> > tcpl.Start();
> >
> > Console.WriteLine("Waiting for clients to connect");
> > Console.WriteLine("Press Ctrl+c to Quit...");
> >
> > while (true)
> > {
> > // Accept will block until someone connects
> > Socket s = tcpl.Accept();
> >
> > // Get the current date and time then concatenate it
> > // into a string
> > now = DateTime.Now;
> > strDateLine = now.ToShortDateString() + " " +
> > now.ToLongTimeString();
> >
> > // Convert the string to a Byte Array & send it
> > Byte[] byteDateLine =
> > ASCII.GetBytes(strDateLine.ToCharArray());
> > s.Send(byteDateLine, byteDateLine.Length, 0);
> > Console.WriteLine("Sent " + strDateLine);
> > }
> > }
> > }
> >
> > /* End Code */
> >
> >
> >
> >
>
>
Greg Huber at 2007-11-11 22:32:22 >
# 5 Re: C# Example
That was definitely a good tip I'll use.

On namespaces, I don't think Using declarations add size to your code in the
way C/C++ #include statements do. They're more like logical controls to
make sure you're running the code you intend, rather than something else
with the same name.

--
Joe Mayo
C# Station - Information, Links, and Other
Resources for the C# Programming Language
http://www.csharp-station.com/

"Greg Huber" <ghuber@NOSPAMPLEASEhcr-manorcare.com> wrote in message
news:39982f62@news.dev-archive.com...
> Yeah, playing around always seems to be the best way to figure it out!
I'll
> agree on that one :) I wonder what harm is done including extra namespaces
> when you don't need them, maybe just a bigger EXE? (ie, similar to C++).
> I'll have to dig up the documentation on the reference that you're
> mentioning so I don't have to be lazy.
>
> Thanks for the advice!
>
> Greg
>
>
>
> "Oscar" <consulBanana@hotmail.com> wrote in message
> news:39982ac4$1@news.dev-archive.com...
> > You'll notice that a lot of people have been having problems with
> > compilations, especially on examples. I posted a similar problem with
> XML,
> > but the revelation hit me a couple of hours later. When you're
compiling
> an
> > example, check out the listing in the reference. Someone who knows a
> little
> > more about assemblies than me could add some detail here, but the name
of
> > the dll you need to include will be listed in the Requirements section
of
> > the class members. For example, if you grab one of the classes under
> > System.Net, you'll see System.net.dll listed as the required assembly.
> >
> > Alternatively, you can do like I did the first time: Go to %system
> > root%/ComPlus/v2000.14.1812, and start including relavent looking dlls
> until
> > it compiles :)
> >
Joe Mayo at 2007-11-11 22:33:27 >
# 6 Re: C# Example
You are correct. All that a using statement does is allow you to use a
shorter name. The following are equivalent:

using System.Text.RegularExpressions;
...
Regex r = new Regex();

and

System.Text.RegularExpressions.Regex r = new
System.Text.RegularExpressions.Regex();

Even with the using statement, I still need to reference
system.text.regularexpressions.dll to get my code to compile.

"Joe Mayo" <mayoj@NOSPAMuswest.net> wrote in message
news:3998b429@news.dev-archive.com...
> That was definitely a good tip I'll use.
>
> On namespaces, I don't think Using declarations add size to your code in
the
> way C/C++ #include statements do. They're more like logical controls to
> make sure you're running the code you intend, rather than something else
> with the same name.
>
> --
> Joe Mayo
> C# Station - Information, Links, and Other
> Resources for the C# Programming Language
> http://www.csharp-station.com/
>
>
> "Greg Huber" <ghuber@NOSPAMPLEASEhcr-manorcare.com> wrote in message
> news:39982f62@news.dev-archive.com...
> > Yeah, playing around always seems to be the best way to figure it out!
> I'll
> > agree on that one :) I wonder what harm is done including extra
namespaces
> > when you don't need them, maybe just a bigger EXE? (ie, similar to C++).
> > I'll have to dig up the documentation on the reference that you're
> > mentioning so I don't have to be lazy.
> >
> > Thanks for the advice!
> >
> > Greg
> >
> >
> >
> > "Oscar" <consulBanana@hotmail.com> wrote in message
> > news:39982ac4$1@news.dev-archive.com...
> > > You'll notice that a lot of people have been having problems with
> > > compilations, especially on examples. I posted a similar problem with
> > XML,
> > > but the revelation hit me a couple of hours later. When you're
> compiling
> > an
> > > example, check out the listing in the reference. Someone who knows a
> > little
> > > more about assemblies than me could add some detail here, but the name
> of
> > > the dll you need to include will be listed in the Requirements section
> of
> > > the class members. For example, if you grab one of the classes under
> > > System.Net, you'll see System.net.dll listed as the required assembly.
> > >
> > > Alternatively, you can do like I did the first time: Go to %system
> > > root%/ComPlus/v2000.14.1812, and start including relavent looking dlls
> > until
> > > it compiles :)
> > >
>
>
>
Eric Gunnerson at 2007-11-11 22:34:26 >
# 7 Re: C# Example
"Joe Mayo" <mayoj@NOSPAMuswest.net> wrote in message
news:3998b429@news.dev-archive.com...
> On namespaces, I don't think Using declarations add size to your code in
the
> way C/C++ #include statements do.

Adding unnecessary #include statements in you C/C++ code, shouldn't
increase the EXE size either.

--
Truth,
James Curran
http://www.NJTheater.com (Professional)
http://www.NovelTheory.com (Personal)
http://www.BrandsForLess.com (Day Job)
James Curran at 2007-11-11 22:35:23 >
# 8 Re: C# Example
Warning: lengthy monologue below

I think there's an issue here that I'm struggling with on the issue of
namespaces. It's probably more of a philosophical one than a clear-cut one.

#1
On one hand, you've got fully qualified names, writing out
System.Console.WriteLine() every time you want to print something. Anyone
who knows the framework knows exactly what you're trying to do. But if I'm
playing with XML right now(which I am), I have to change a bunch of code
when System.NewXml... becomes just System.Xml in the Beta. It's also makes
for really, really long lines and a lot of finger cramps.

#2
On the other hand, you've got aliases. I've been trying the alias/namespace
stuff:
using sysCon = System.Console;

to save a couple of keystrokes, and
using System.NewXml;

That's pretty nice because it makes a clean trade-off with the first
scenario. Easy to type, more aesthetically pleasing, and easy to change
when my class changes names or I derive my own custom class. But another
programmer (possibly even my future self) has to take some extra brain
cycles to resolve the name.

##
I think I prefere #2 over #1, mostly for my present convenience. Out of the
two methods in #2, the first seems preferable, since it doesn't dump a whole
host of functions(most of which I won't be using) into my namespace. It
also feels like more of a Good Thing(tm), since even if a future programmer
needs to resolve the name, at least it's always clear(eventually) that I'm
using something from a particular framework namespace or class, not
something hidden in another one of my own files.

So my question, after all that, is about best practices. I can see my
current usage turning into a huge nightmare on a large project, so I'd like
to get it straight while I'm starting from someone who's had some experience
dealing with these things. Is there some naming convention you(the plural)
use to manage the mess? Is there a time when it's a Good Thing(tm) to dump
the namespace without an alias?

"Eric Gunnerson" <ericgu@nospam.microsoft.nospam.com> wrote in message
news:39995d40@news.dev-archive.com...
> You are correct. All that a using statement does is allow you to use a
> shorter name. The following are equivalent:
>
> using System.Text.RegularExpressions;
> ...
> Regex r = new Regex();
>
> and
>
> System.Text.RegularExpressions.Regex r = new
> System.Text.RegularExpressions.Regex();
>
> Even with the using statement, I still need to reference
> system.text.regularexpressions.dll to get my code to compile.
>
> "Joe Mayo" <mayoj@NOSPAMuswest.net> wrote in message
> news:3998b429@news.dev-archive.com...
> > That was definitely a good tip I'll use.
> >
> > On namespaces, I don't think Using declarations add size to your code in
> the
> > way C/C++ #include statements do. They're more like logical controls to
> > make sure you're running the code you intend, rather than something else
> > with the same name.
> >
> > --
> > Joe Mayo
> > C# Station - Information, Links, and Other
> > Resources for the C# Programming Language
> > http://www.csharp-station.com/
> >
> >
> > "Greg Huber" <ghuber@NOSPAMPLEASEhcr-manorcare.com> wrote in message
> > news:39982f62@news.dev-archive.com...
> > > Yeah, playing around always seems to be the best way to figure it out!
> > I'll
> > > agree on that one :) I wonder what harm is done including extra
> namespaces
> > > when you don't need them, maybe just a bigger EXE? (ie, similar to
C++).
> > > I'll have to dig up the documentation on the reference that you're
> > > mentioning so I don't have to be lazy.
> > >
> > > Thanks for the advice!
> > >
> > > Greg
> > >
> > >
> > >
> > > "Oscar" <consulBanana@hotmail.com> wrote in message
> > > news:39982ac4$1@news.dev-archive.com...
> > > > You'll notice that a lot of people have been having problems with
> > > > compilations, especially on examples. I posted a similar problem
with
> > > XML,
> > > > but the revelation hit me a couple of hours later. When you're
> > compiling
> > > an
> > > > example, check out the listing in the reference. Someone who knows
a
> > > little
> > > > more about assemblies than me could add some detail here, but the
name
> > of
> > > > the dll you need to include will be listed in the Requirements
section
> > of
> > > > the class members. For example, if you grab one of the classes
under
> > > > System.Net, you'll see System.net.dll listed as the required
assembly.
> > > >
> > > > Alternatively, you can do like I did the first time: Go to %system
> > > > root%/ComPlus/v2000.14.1812, and start including relavent looking
dlls
> > > until
> > > > it compiles :)
> > > >
> >
> >
> >
>
>
Oscar at 2007-11-11 22:36:21 >
# 9 Re: C# Example
All the reference I wrote about should have come with your sdk. It's the
sdkstart.chm file buried in the sdk folder under docs. If you're familiar
with the general layout of MSDN stuff, it'll be a cinch. If you're
not...whoa. When I was introduced to MSDN for the first time, I couldn't
find the same article twice for about three months :)

"Greg Huber" <ghuber@NOSPAMPLEASEhcr-manorcare.com> wrote in message
news:39982f62@news.dev-archive.com...
> Yeah, playing around always seems to be the best way to figure it out!
I'll
> agree on that one :) I wonder what harm is done including extra namespaces
> when you don't need them, maybe just a bigger EXE? (ie, similar to C++).
> I'll have to dig up the documentation on the reference that you're
> mentioning so I don't have to be lazy.
>
> Thanks for the advice!
>
> Greg
>
>
>
> "Oscar" <consulBanana@hotmail.com> wrote in message
> news:39982ac4$1@news.dev-archive.com...
> > You'll notice that a lot of people have been having problems with
> > compilations, especially on examples. I posted a similar problem with
> XML,
> > but the revelation hit me a couple of hours later. When you're
compiling
> an
> > example, check out the listing in the reference. Someone who knows a
> little
> > more about assemblies than me could add some detail here, but the name
of
> > the dll you need to include will be listed in the Requirements section
of
> > the class members. For example, if you grab one of the classes under
> > System.Net, you'll see System.net.dll listed as the required assembly.
> >
> > Alternatively, you can do like I did the first time: Go to %system
> > root%/ComPlus/v2000.14.1812, and start including relavent looking dlls
> until
> > it compiles :)
> >
> > "Greg Huber" <ghuber@NOSPAMPLEASEhcr-manorcare.com> wrote in message
> > news:3997e97a$1@news.dev-archive.com...
> > > I found the code sample below on the microsoft web site that allows
you
> to
> > > create a simple TCP listener with c#:
> > >
> >
>
http://msdn.microsoft.com/library/default.asp?URL=/library/techart/PDC_websv
> > > c.htm
> > >
> > > But when I compile I get this error:
> > >
> > > Server.cs(2,14): error CS0234: The type or namespace name 'Net' does
not
> > > exist i
> > > n the class or namespace 'System'
> > > Server.cs(3,14): error CS0234: The type or namespace name 'Net' does
not
> > > exist i
> > > n the class or namespace 'System'
> > >
> > > Is there something I'm not doing right? How do I get the Net classes?
> (Did
> > > they not come with the NGWS preview)?
> > >
> > > Thanks,
> > > Greg
> > >
> > > /* Begin Code */
> > > using System;
> > > using System.Net;
> > > using System.Net.Sockets;
> > > using System.Text;
> > >
> > > class Server
> > > {
> > > public static void Main()
> > > {
> > > DateTime now;
> > > String strDateLine;
> > > Encoding ASCII = Encoding.ASCII;
> > >
> > > // listen on port 23
> > > TCPListener tcpl = new TCPListener(23);
> > >
> > > tcpl.Start();
> > >
> > > Console.WriteLine("Waiting for clients to connect");
> > > Console.WriteLine("Press Ctrl+c to Quit...");
> > >
> > > while (true)
> > > {
> > > // Accept will block until someone connects
> > > Socket s = tcpl.Accept();
> > >
> > > // Get the current date and time then concatenate it
> > > // into a string
> > > now = DateTime.Now;
> > > strDateLine = now.ToShortDateString() + " " +
> > > now.ToLongTimeString();
> > >
> > > // Convert the string to a Byte Array & send it
> > > Byte[] byteDateLine =
> > > ASCII.GetBytes(strDateLine.ToCharArray());
> > > s.Send(byteDateLine, byteDateLine.Length, 0);
> > > Console.WriteLine("Sent " + strDateLine);
> > > }
> > > }
> > > }
> > >
> > > /* End Code */
> > >
> > >
> > >
> > >
> >
> >
>
>
Oscar at 2007-11-11 22:37:23 >
# 10 Re: C# Example
cpref.chm seems to have everything listed, but what would really be nice is
a document that has a one-to-one mapping of namespace to assembly for
example:

System.Data.ADO -- System.Data.dll
System.Net -- System.Net.dll
System.Runtime.InteropServices -- mscorlib.dll

or even:
System.Data.DLL
--List of namespaces

System.Net.dll
--List of namespaces

Maybe there is and I haven't found it yet.. :)

"Oscar" <consulBanana@hotmail.com> wrote in message
news:39997af1$1@news.dev-archive.com...
> All the reference I wrote about should have come with your sdk. It's the
> sdkstart.chm file buried in the sdk folder under docs. If you're familiar
> with the general layout of MSDN stuff, it'll be a cinch. If you're
> not...whoa. When I was introduced to MSDN for the first time, I couldn't
> find the same article twice for about three months :)
>
> "Greg Huber" <ghuber@NOSPAMPLEASEhcr-manorcare.com> wrote in message
> news:39982f62@news.dev-archive.com...
> > Yeah, playing around always seems to be the best way to figure it out!
> I'll
> > agree on that one :) I wonder what harm is done including extra
namespaces
> > when you don't need them, maybe just a bigger EXE? (ie, similar to C++).
> > I'll have to dig up the documentation on the reference that you're
> > mentioning so I don't have to be lazy.
> >
> > Thanks for the advice!
> >
> > Greg
> >
> >
> >
> > "Oscar" <consulBanana@hotmail.com> wrote in message
> > news:39982ac4$1@news.dev-archive.com...
> > > You'll notice that a lot of people have been having problems with
> > > compilations, especially on examples. I posted a similar problem with
> > XML,
> > > but the revelation hit me a couple of hours later. When you're
> compiling
> > an
> > > example, check out the listing in the reference. Someone who knows a
> > little
> > > more about assemblies than me could add some detail here, but the name
> of
> > > the dll you need to include will be listed in the Requirements section
> of
> > > the class members. For example, if you grab one of the classes under
> > > System.Net, you'll see System.net.dll listed as the required assembly.
> > >
> > > Alternatively, you can do like I did the first time: Go to %system
> > > root%/ComPlus/v2000.14.1812, and start including relavent looking dlls
> > until
> > > it compiles :)
> > >
> > > "Greg Huber" <ghuber@NOSPAMPLEASEhcr-manorcare.com> wrote in message
> > > news:3997e97a$1@news.dev-archive.com...
> > > > I found the code sample below on the microsoft web site that allows
> you
> > to
> > > > create a simple TCP listener with c#:
> > > >
> > >
> >
>
http://msdn.microsoft.com/library/default.asp?URL=/library/techart/PDC_websv
> > > > c.htm
> > > >
> > > > But when I compile I get this error:
> > > >
> > > > Server.cs(2,14): error CS0234: The type or namespace name 'Net' does
> not
> > > > exist i
> > > > n the class or namespace 'System'
> > > > Server.cs(3,14): error CS0234: The type or namespace name 'Net' does
> not
> > > > exist i
> > > > n the class or namespace 'System'
> > > >
> > > > Is there something I'm not doing right? How do I get the Net
classes?
> > (Did
> > > > they not come with the NGWS preview)?
> > > >
> > > > Thanks,
> > > > Greg
> > > >
> > > > /* Begin Code */
> > > > using System;
> > > > using System.Net;
> > > > using System.Net.Sockets;
> > > > using System.Text;
> > > >
> > > > class Server
> > > > {
> > > > public static void Main()
> > > > {
> > > > DateTime now;
> > > > String strDateLine;
> > > > Encoding ASCII = Encoding.ASCII;
> > > >
> > > > // listen on port 23
> > > > TCPListener tcpl = new TCPListener(23);
> > > >
> > > > tcpl.Start();
> > > >
> > > > Console.WriteLine("Waiting for clients to connect");
> > > > Console.WriteLine("Press Ctrl+c to Quit...");
> > > >
> > > > while (true)
> > > > {
> > > > // Accept will block until someone connects
> > > > Socket s = tcpl.Accept();
> > > >
> > > > // Get the current date and time then concatenate it
> > > > // into a string
> > > > now = DateTime.Now;
> > > > strDateLine = now.ToShortDateString() + " " +
> > > > now.ToLongTimeString();
> > > >
> > > > // Convert the string to a Byte Array & send it
> > > > Byte[] byteDateLine =
> > > > ASCII.GetBytes(strDateLine.ToCharArray());
> > > > s.Send(byteDateLine, byteDateLine.Length, 0);
> > > > Console.WriteLine("Sent " + strDateLine);
> > > > }
> > > > }
> > > > }
> > > >
> > > > /* End Code */
> > > >
> > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>
Greg Huber at 2007-11-11 22:38:30 >
# 11 Re: C# Example
Personally, I don't use the alias version unless it's necessary (and it
hasn't been for the code I've written yet). I tend to add the appropriate
using statements, and then just use the single-word version of the names.

Does that answer your question, or did I misunderstand you?

"Oscar" <consulBanana@hotmail.com> wrote in message
news:39997825$1@news.dev-archive.com...
> Warning: lengthy monologue below
>
> I think there's an issue here that I'm struggling with on the issue of
> namespaces. It's probably more of a philosophical one than a clear-cut
one.
>
> #1
> On one hand, you've got fully qualified names, writing out
> System.Console.WriteLine() every time you want to print something. Anyone
> who knows the framework knows exactly what you're trying to do. But if
I'm
> playing with XML right now(which I am), I have to change a bunch of code
> when System.NewXml... becomes just System.Xml in the Beta. It's also
makes
> for really, really long lines and a lot of finger cramps.
>
> #2
> On the other hand, you've got aliases. I've been trying the
alias/namespace
> stuff:
> using sysCon = System.Console;
>
> to save a couple of keystrokes, and
> using System.NewXml;
>
> That's pretty nice because it makes a clean trade-off with the first
> scenario. Easy to type, more aesthetically pleasing, and easy to change
> when my class changes names or I derive my own custom class. But another
> programmer (possibly even my future self) has to take some extra brain
> cycles to resolve the name.
>
> ##
> I think I prefere #2 over #1, mostly for my present convenience. Out of
the
> two methods in #2, the first seems preferable, since it doesn't dump a
whole
> host of functions(most of which I won't be using) into my namespace. It
> also feels like more of a Good Thing(tm), since even if a future
programmer
> needs to resolve the name, at least it's always clear(eventually) that I'm
> using something from a particular framework namespace or class, not
> something hidden in another one of my own files.
>
> So my question, after all that, is about best practices. I can see my
> current usage turning into a huge nightmare on a large project, so I'd
like
> to get it straight while I'm starting from someone who's had some
experience
> dealing with these things. Is there some naming convention you(the
plural)
> use to manage the mess? Is there a time when it's a Good Thing(tm) to
dump
> the namespace without an alias?
>
> "Eric Gunnerson" <ericgu@nospam.microsoft.nospam.com> wrote in message
> news:39995d40@news.dev-archive.com...
> > You are correct. All that a using statement does is allow you to use a
> > shorter name. The following are equivalent:
> >
> > using System.Text.RegularExpressions;
> > ...
> > Regex r = new Regex();
> >
> > and
> >
> > System.Text.RegularExpressions.Regex r = new
> > System.Text.RegularExpressions.Regex();
> >
> > Even with the using statement, I still need to reference
> > system.text.regularexpressions.dll to get my code to compile.
> >
> > "Joe Mayo" <mayoj@NOSPAMuswest.net> wrote in message
> > news:3998b429@news.dev-archive.com...
> > > That was definitely a good tip I'll use.
> > >
> > > On namespaces, I don't think Using declarations add size to your code
in
> > the
> > > way C/C++ #include statements do. They're more like logical controls
to
> > > make sure you're running the code you intend, rather than something
else
> > > with the same name.
> > >
> > > --
> > > Joe Mayo
> > > C# Station - Information, Links, and Other
> > > Resources for the C# Programming Language
> > > http://www.csharp-station.com/
> > >
> > >
> > > "Greg Huber" <ghuber@NOSPAMPLEASEhcr-manorcare.com> wrote in message
> > > news:39982f62@news.dev-archive.com...
> > > > Yeah, playing around always seems to be the best way to figure it
out!
> > > I'll
> > > > agree on that one :) I wonder what harm is done including extra
> > namespaces
> > > > when you don't need them, maybe just a bigger EXE? (ie, similar to
> C++).
> > > > I'll have to dig up the documentation on the reference that you're
> > > > mentioning so I don't have to be lazy.
> > > >
> > > > Thanks for the advice!
> > > >
> > > > Greg
> > > >
> > > >
> > > >
> > > > "Oscar" <consulBanana@hotmail.com> wrote in message
> > > > news:39982ac4$1@news.dev-archive.com...
> > > > > You'll notice that a lot of people have been having problems with
> > > > > compilations, especially on examples. I posted a similar problem
> with
> > > > XML,
> > > > > but the revelation hit me a couple of hours later. When you're
> > > compiling
> > > > an
> > > > > example, check out the listing in the reference. Someone who
knows
> a
> > > > little
> > > > > more about assemblies than me could add some detail here, but the
> name
> > > of
> > > > > the dll you need to include will be listed in the Requirements
> section
> > > of
> > > > > the class members. For example, if you grab one of the classes
> under
> > > > > System.Net, you'll see System.net.dll listed as the required
> assembly.
> > > > >
> > > > > Alternatively, you can do like I did the first time: Go to
%system
> > > > > root%/ComPlus/v2000.14.1812, and start including relavent looking
> dlls
> > > > until
> > > > > it compiles :)
> > > > >
> > >
> > >
> > >
> >
> >
>
>
Eric Gunnerson at 2007-11-11 22:39:33 >
# 12 Re: C# Example
I've been looking for the same thing, actually. So far these are the only
tools I've seen:

1)those .chm files
2)ildasm.exe (in %sdk root%/bin)(takes a .dll apart for you - kind of the
inverse fn)
3)WinCV.exe (same place)
4)the example(can't remember what it is 'cause I couldn't get it to compile
5)the "random include" method mentioned previously

WinCV is probably one of your best options, though I couldn't get it to load
up just now(I need to raid one of the other office machines for memory ;) )
It probably wouldn't be too hard to extend that program or write a similar
one, but I probably won't make it to winForms for a while now.

"Greg Huber" <ghuber@NOSPAMPLEASEhcr-manorcare.com> wrote in message
news:39998278$1@news.dev-archive.com...
> cpref.chm seems to have everything listed, but what would really be nice
is
> a document that has a one-to-one mapping of namespace to assembly for
> example:
>
> System.Data.ADO -- System.Data.dll
> System.Net -- System.Net.dll
> System.Runtime.InteropServices -- mscorlib.dll
>
> or even:
> System.Data.DLL
> --List of namespaces
>
> System.Net.dll
> --List of namespaces
>
> Maybe there is and I haven't found it yet.. :)
>
> "Oscar" <consulBanana@hotmail.com> wrote in message
> news:39997af1$1@news.dev-archive.com...
> > All the reference I wrote about should have come with your sdk. It's
the
> > sdkstart.chm file buried in the sdk folder under docs. If you're
familiar
> > with the general layout of MSDN stuff, it'll be a cinch. If you're
> > not...whoa. When I was introduced to MSDN for the first time, I
couldn't
> > find the same article twice for about three months :)
> >
> > "Greg Huber" <ghuber@NOSPAMPLEASEhcr-manorcare.com> wrote in message
> > news:39982f62@news.dev-archive.com...
> > > Yeah, playing around always seems to be the best way to figure it out!
> > I'll
> > > agree on that one :) I wonder what harm is done including extra
> namespaces
> > > when you don't need them, maybe just a bigger EXE? (ie, similar to
C++).
> > > I'll have to dig up the documentation on the reference that you're
> > > mentioning so I don't have to be lazy.
> > >
> > > Thanks for the advice!
> > >
> > > Greg
> > >
> > >
> > >
> > > "Oscar" <consulBanana@hotmail.com> wrote in message
> > > news:39982ac4$1@news.dev-archive.com...
> > > > You'll notice that a lot of people have been having problems with
> > > > compilations, especially on examples. I posted a similar problem
with
> > > XML,
> > > > but the revelation hit me a couple of hours later. When you're
> > compiling
> > > an
> > > > example, check out the listing in the reference. Someone who knows
a
> > > little
> > > > more about assemblies than me could add some detail here, but the
name
> > of
> > > > the dll you need to include will be listed in the Requirements
section
> > of
> > > > the class members. For example, if you grab one of the classes
under
> > > > System.Net, you'll see System.net.dll listed as the required
assembly.
> > > >
> > > > Alternatively, you can do like I did the first time: Go to %system
> > > > root%/ComPlus/v2000.14.1812, and start including relavent looking
dlls
> > > until
> > > > it compiles :)
> > > >
> > > > "Greg Huber" <ghuber@NOSPAMPLEASEhcr-manorcare.com> wrote in message
> > > > news:3997e97a$1@news.dev-archive.com...
> > > > > I found the code sample below on the microsoft web site that
allows
> > you
> > > to
> > > > > create a simple TCP listener with c#:
> > > > >
> > > >
> > >
> >
>
http://msdn.microsoft.com/library/default.asp?URL=/library/techart/PDC_websv
> > > > > c.htm
> > > > >
> > > > > But when I compile I get this error:
> > > > >
> > > > > Server.cs(2,14): error CS0234: The type or namespace name 'Net'
does
> > not
> > > > > exist i
> > > > > n the class or namespace 'System'
> > > > > Server.cs(3,14): error CS0234: The type or namespace name 'Net'
does
> > not
> > > > > exist i
> > > > > n the class or namespace 'System'
> > > > >
> > > > > Is there something I'm not doing right? How do I get the Net
> classes?
> > > (Did
> > > > > they not come with the NGWS preview)?
> > > > >
> > > > > Thanks,
> > > > > Greg
> > > > >
> > > > > /* Begin Code */
> > > > > using System;
> > > > > using System.Net;
> > > > > using System.Net.Sockets;
> > > > > using System.Text;
> > > > >
> > > > > class Server
> > > > > {
> > > > > public static void Main()
> > > > > {
> > > > > DateTime now;
> > > > > String strDateLine;
> > > > > Encoding ASCII = Encoding.ASCII;
> > > > >
> > > > > // listen on port 23
> > > > > TCPListener tcpl = new TCPListener(23);
> > > > >
> > > > > tcpl.Start();
> > > > >
> > > > > Console.WriteLine("Waiting for clients to connect");
> > > > > Console.WriteLine("Press Ctrl+c to Quit...");
> > > > >
> > > > > while (true)
> > > > > {
> > > > > // Accept will block until someone connects
> > > > > Socket s = tcpl.Accept();
> > > > >
> > > > > // Get the current date and time then concatenate it
> > > > > // into a string
> > > > > now = DateTime.Now;
> > > > > strDateLine = now.ToShortDateString() + " " +
> > > > > now.ToLongTimeString();
> > > > >
> > > > > // Convert the string to a Byte Array & send it
> > > > > Byte[] byteDateLine =
> > > > > ASCII.GetBytes(strDateLine.ToCharArray());
> > > > > s.Send(byteDateLine, byteDateLine.Length, 0);
> > > > > Console.WriteLine("Sent " + strDateLine);
> > > > > }
> > > > > }
> > > > > }
> > > > >
> > > > > /* End Code */
> > > > >
> > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>
Oscar at 2007-11-11 22:40:26 >
# 13 Re: C# Example
Most definitely! I just want some opinions to get a feeling for how people
are using them. Didn't know if there were any "holy wars" on the subject,
or maybe some accepted practice amongst the namespace-saavy. It seems like
a really great tool that has a potential for abuse.

"Eric Gunnerson" <ericgu@nospam.microsoft.nospam.com> wrote in message
news:399992c0@news.dev-archive.com...
> Personally, I don't use the alias version unless it's necessary (and it
> hasn't been for the code I've written yet). I tend to add the appropriate
> using statements, and then just use the single-word version of the names.
>
> Does that answer your question, or did I misunderstand you?
>
>
> "Oscar" <consulBanana@hotmail.com> wrote in message
> news:39997825$1@news.dev-archive.com...
> > Warning: lengthy monologue below
> >
> > I think there's an issue here that I'm struggling with on the issue of
> > namespaces. It's probably more of a philosophical one than a clear-cut
> one.
> >
> > #1
> > On one hand, you've got fully qualified names, writing out
> > System.Console.WriteLine() every time you want to print something.
Anyone
> > who knows the framework knows exactly what you're trying to do. But if
> I'm
> > playing with XML right now(which I am), I have to change a bunch of code
> > when System.NewXml... becomes just System.Xml in the Beta. It's also
> makes
> > for really, really long lines and a lot of finger cramps.
> >
> > #2
> > On the other hand, you've got aliases. I've been trying the
> alias/namespace
> > stuff:
> > using sysCon = System.Console;
> >
> > to save a couple of keystrokes, and
> > using System.NewXml;
> >
> > That's pretty nice because it makes a clean trade-off with the first
> > scenario. Easy to type, more aesthetically pleasing, and easy to change
> > when my class changes names or I derive my own custom class. But
another
> > programmer (possibly even my future self) has to take some extra brain
> > cycles to resolve the name.
> >
> > ##
> > I think I prefere #2 over #1, mostly for my present convenience. Out of
> the
> > two methods in #2, the first seems preferable, since it doesn't dump a
> whole
> > host of functions(most of which I won't be using) into my namespace. It
> > also feels like more of a Good Thing(tm), since even if a future
> programmer
> > needs to resolve the name, at least it's always clear(eventually) that
I'm
> > using something from a particular framework namespace or class, not
> > something hidden in another one of my own files.
> >
> > So my question, after all that, is about best practices. I can see my
> > current usage turning into a huge nightmare on a large project, so I'd
> like
> > to get it straight while I'm starting from someone who's had some
> experience
> > dealing with these things. Is there some naming convention you(the
> plural)
> > use to manage the mess? Is there a time when it's a Good Thing(tm) to
> dump
> > the namespace without an alias?
> >
> > "Eric Gunnerson" <ericgu@nospam.microsoft.nospam.com> wrote in message
> > news:39995d40@news.dev-archive.com...
> > > You are correct. All that a using statement does is allow you to use a
> > > shorter name. The following are equivalent:
> > >
> > > using System.Text.RegularExpressions;
> > > ...
> > > Regex r = new Regex();
> > >
> > > and
> > >
> > > System.Text.RegularExpressions.Regex r = new
> > > System.Text.RegularExpressions.Regex();
> > >
> > > Even with the using statement, I still need to reference
> > > system.text.regularexpressions.dll to get my code to compile.
> > >
> > > "Joe Mayo" <mayoj@NOSPAMuswest.net> wrote in message
> > > news:3998b429@news.dev-archive.com...
> > > > That was definitely a good tip I'll use.
> > > >
> > > > On namespaces, I don't think Using declarations add size to your
code
> in
> > > the
> > > > way C/C++ #include statements do. They're more like logical
controls
> to
> > > > make sure you're running the code you intend, rather than something
> else
> > > > with the same name.
> > > >
> > > > --
> > > > Joe Mayo
> > > > C# Station - Information, Links, and Other
> > > > Resources for the C# Programming Language
> > > > http://www.csharp-station.com/
> > > >
> > > >
> > > > "Greg Huber" <ghuber@NOSPAMPLEASEhcr-manorcare.com> wrote in message
> > > > news:39982f62@news.dev-archive.com...
> > > > > Yeah, playing around always seems to be the best way to figure it
> out!
> > > > I'll
> > > > > agree on that one :) I wonder what harm is done including extra
> > > namespaces
> > > > > when you don't need them, maybe just a bigger EXE? (ie, similar to
> > C++).
> > > > > I'll have to dig up the documentation on the reference that you're
> > > > > mentioning so I don't have to be lazy.
> > > > >
> > > > > Thanks for the advice!
> > > > >
> > > > > Greg
> > > > >
> > > > >
> > > > >
> > > > > "Oscar" <consulBanana@hotmail.com> wrote in message
> > > > > news:39982ac4$1@news.dev-archive.com...
> > > > > > You'll notice that a lot of people have been having problems
with
> > > > > > compilations, especially on examples. I posted a similar
problem
> > with
> > > > > XML,
> > > > > > but the revelation hit me a couple of hours later. When you're
> > > > compiling
> > > > > an
> > > > > > example, check out the listing in the reference. Someone who
> knows
> > a
> > > > > little
> > > > > > more about assemblies than me could add some detail here, but
the
> > name
> > > > of
> > > > > > the dll you need to include will be listed in the Requirements
> > section
> > > > of
> > > > > > the class members. For example, if you grab one of the classes
> > under
> > > > > > System.Net, you'll see System.net.dll listed as the required
> > assembly.
> > > > > >
> > > > > > Alternatively, you can do like I did the first time: Go to
> %system
> > > > > > root%/ComPlus/v2000.14.1812, and start including relavent
looking
> > dlls
> > > > > until
> > > > > > it compiles :)
> > > > > >
> > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>
Oscar at 2007-11-11 22:41:26 >
# 14 Re: C# Example
Ada has something similar where you use the keyword "with" instead of
"using". I've seen some people break into heated debates over the potential
confusion caused by not using the fully qualified name on every statement.
Personally, I'm a tad more moderate on the subject. I believe that the
purpose and nature of the code itself should drive your decision. For
instance, let's look at both sides of one issue that could arise. If you
were working on a RAD prototype that you were going to throw away in short
order, you'd use every shortcut you could - i.e. "using" declarations for
everything. However, if you had a mission critical system projected for a
long life in maintenance, you would probably lean toward clarity - i.e.
fully qualified names everywhere.

Regardless of the style you adopt, consistency will make your code more
maintainable.

--
Joe Mayo
C# Station - Information, Links, and Other
Resources for the C# Programming Language
http://www.csharp-station.com/

"Oscar" <consulBanana@hotmail.com> wrote in message
news:39997825$1@news.dev-archive.com...
> Warning: lengthy monologue below
>
> That's pretty nice because it makes a clean trade-off with the first
> scenario. Easy to type, more aesthetically pleasing, and easy to change
> when my class changes names or I derive my own custom class. But another
> programmer (possibly even my future self) has to take some extra brain
> cycles to resolve the name.
>
> ##
> I think I prefere #2 over #1, mostly for my present convenience. Out of
the
> two methods in #2, the first seems preferable, since it doesn't dump a
whole
> host of functions(most of which I won't be using) into my namespace. It
> also feels like more of a Good Thing(tm), since even if a future
programmer
> needs to resolve the name, at least it's always clear(eventually) that I'm
> using something from a particular framework namespace or class, not
> something hidden in another one of my own files.
>
> So my question, after all that, is about best practices. I can see my
> current usage turning into a huge nightmare on a large project, so I'd
like
> to get it straight while I'm starting from someone who's had some
experience
> dealing with these things. Is there some naming convention you(the
plural)
> use to manage the mess? Is there a time when it's a Good Thing(tm) to
dump
> the namespace without an alias?
>
> "Eric Gunnerson" <ericgu@nospam.microsoft.nospam.com> wrote in message
> news:39995d40@news.dev-archive.com...
> > You are correct. All that a using statement does is allow you to use a
> > shorter name. The following are equivalent:
> >
> > using System.Text.RegularExpressions;
> > ...
> > Regex r = new Regex();
> >
> > and
> >
> > System.Text.RegularExpressions.Regex r = new
> > System.Text.RegularExpressions.Regex();
> >
> > Even with the using statement, I still need to reference
> > system.text.regularexpressions.dll to get my code to compile.
> >
> > "Joe Mayo" <mayoj@NOSPAMuswest.net> wrote in message
> > news:3998b429@news.dev-archive.com...
> > > That was definitely a good tip I'll use.
> > >
> > > On namespaces, I don't think Using declarations add size to your code
in
> > the
> > > way C/C++ #include statements do. They're more like logical controls
to
> > > make sure you're running the code you intend, rather than something
else
> > > with the same name.
> > >
> > > --
> > > Joe Mayo
> > > C# Station - Information, Links, and Other
> > > Resources for the C# Programming Language
> > > http://www.csharp-station.com/
> > >
> > >
> > > "Greg Huber" <ghuber@NOSPAMPLEASEhcr-manorcare.com> wrote in message
> > > news:39982f62@news.dev-archive.com...
> > > > Yeah, playing around always seems to be the best way to figure it
out!
> > > I'll
> > > > agree on that one :) I wonder what harm is done including extra
> > namespaces
> > > > when you don't need them, maybe just a bigger EXE? (ie, similar to
> C++).
> > > > I'll have to dig up the documentation on the reference that you're
> > > > mentioning so I don't have to be lazy.
> > > >
> > > > Thanks for the advice!
> > > >
> > > > Greg
> > > >
> > > >
> > > >
> > > > "Oscar" <consulBanana@hotmail.com> wrote in message
> > > > news:39982ac4$1@news.dev-archive.com...
> > > > > You'll notice that a lot of people have been having problems with
> > > > > compilations, especially on examples. I posted a similar problem
> with
> > > > XML,
> > > > > but the revelation hit me a couple of hours later. When you're
> > > compiling
> > > > an
> > > > > example, check out the listing in the reference. Someone who
knows
> a
> > > > little
> > > > > more about assemblies than me could add some detail here, but the
> name
> > > of
> > > > > the dll you need to include will be listed in the Requirements
> section
> > > of
> > > > > the class members. For example, if you grab one of the classes
> under
> > > > > System.Net, you'll see System.net.dll listed as the required
> assembly.
> > > > >
> > > > > Alternatively, you can do like I did the first time: Go to
%system
> > > > > root%/ComPlus/v2000.14.1812, and start including relavent looking
> dlls
> > > > until
> > > > > it compiles :)
> > > > >
> > >
> > >
> > >
> >
> >
>
>
Joe Mayo at 2007-11-11 22:42:27 >
# 15 Re: C# Example
> Ada has something similar where you use the keyword
> "with" instead of "using."

Joe: So does VB. ;-)
--
Phil Weber
Phil Weber at 2007-11-11 22:43:35 >