Unit 1
Unit 1
CTS provide a well-defined set of intrinsic data types used by all .NET aware languages .
.NET Base Type (CTS Data VB.NET Keyword C# Keyword Managed Extensions for C++
Type) Keyword
C# uses (+) operator for string concatenation while in VB .NET we use the
ampersand (&).
The Common Language Specification (CLS) is a set of rules that describe the small and
complete set of features.
These features are supported by a .NET-aware compiler to produce a code that can be
hosted by CLR. Also, this code can be accessed by all languages in the .NET platform.
The CLS can be viewed as a subset of the full functionality defined by the CTS.
public class Calc
{
// Exposed unsigned data is not CLS compliant!
public ulong Add(ulong x, ulong y)
{
return x + y;
public class Calc
} {
} public int Add(int x, int y)
{
// As this ulong variable is only
used internally,
// we are still CLS compliant.
ulong temp;
temp= x+y;
return temp;
}
}
Understanding Common Language Runtime
.NET source code
written in Some .NET compiler
some .NET-aware
Language The root of the CLR is physically
represented by a library named
mscoree.dll (Common Object Runtime
Execution Engine).
DLL or EXE Assembly
(CIL, Metadata and
Manifest) mscoree.dll is loaded automatically, which
in turn loads the required assembly into
memory.
Base Class
.NET Execution Engine (mscoree.dll) The CLR then lays out the type in
Libraries
Class Loader
memory, compiles the associated CIL into
(mscorlib.dll and
so on) platform-specific instructions, performs
any necessary security checks, and then
Jitter
executes the code in question.
Platform-Specific
Instructions
Execute the
application
A Tour of the .NET Namespaces
For example, the System.IO namespace contains file I/O related types, the System.Data
namespace defines basic database types, and so on.
For example, consider following programs written in C#, VB.NET and MC++.
// C# code
using System;
public class Test
{
public static void Main()
{
Console.WrtieLine(“Hello World”);
}
}
// VB.NET code
Imports System
Public Module Test
Sub Main()
Console.WrtieLine(“Hello World”)
End Sub
End Module
// MC++ code
#using <mscorlib.dll>
using namespace System;
void Main()
{
Console::WrtieLine(“Hello World”);
}
.NET Namespace Meaning
System System contains numerous useful types dealing with intrinsic data, mathematical
computations, random number generation, environment variables, and garbage
collection, as well as a number of commonly used exceptions and attributes.
System.Collections.Generic (ArrayList, Queue etc), as well as base types and interfaces that allow you to
build customized collections. As of .NET 2.0, the collection types have been
extended with generic capabilities.
System.IO These namespaces include file I/O, buffering, and so forth. As of .NET 2.0, the
System.IO.Compression IO namespaces now include support compression and port manipulation.
System.IO.Ports
System.Net This namespace (as well as other related namespaces) contains types related to
network programming (requests/responses, sockets, end points, and so on).
System.Windows.Forms This namespace contains types that facilitate the construction of traditional
desktop GUI applications.
System.Xml The XML-centric namespaces contain numerous types used to interact with
XML data.
Accessing a Namespace Programmatically
A namespace is a convenient way to logically understand and organize related types. Consider
the System namespace.
In C#, the using keyword simplifies the process of referencing types defined in a particular
namespace.
class MyApp
{
public void DisplayLogo()
{
// create a 20x20 pixel bitmap.
Bitmap bm = new Bitmap(20, 20);
...
}
}
As this application is referencing System.Drawing, the compiler is able to resolve the Bitmap
class as a member of this namespace.
Deploying the .NET Runtime
Microsoft provides a setup package named dotnetfx.exe that can be freely shipped and installed along with your
custom software.
Once dotnetfx.exe is installed, the target machine will now contain the .NET base class libraries, .NET runtime
(mscoree.dll), and additional .NET infrastructure (such as the GAC, Global Assembly Cashe).