
.NET Platform Fundamentals | 7
Introduction
This is the Title of the Book, eMatter Edition
Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved.
string Line;
while(sr.Peek( ) != -1)
{
Line = sr.ReadLine( );
Response.Write(Server.HtmlEncode(Line) + "<br/>");
}
We preface the name of the class, StreamReader, with its namespace name,
System.IO, to prevent naming collisions with other classes in different assem-
blies that might have the same name and to ensure that we get the
StreamReader
class we expect. We’ll discuss namespaces and assemblies later in this section.
In C#, the lowercase new keyword is used to instantiate classes. In
Visual Basic .NET, the New keyword is uppercase, but since the
Visual Basic language is not case-sensitive, this is a standard prac-
tice, rather than a requirement enforced by the compiler. C#, on
the other hand, is case-sensitive, so keep this in mind when switch-
ing between C# and VB.NET.
Namespaces
Namespaces, a key part of the .NET Framework, provide scope to both prein-
stalled framework classes and custom-developed classes. Namespaces are declared
for a given set of classes (types) by enclosing those classes in one of the following
declarations:
// C#
namespace myNamespace
{
class myClass
{
// class implementation code
}
}
' VB.NET
Namespace myNamespace
Class myCls
' class implementation code
End Class
End Namespace
Namespaces may also be nested, as shown here: ...