Page 32 - DCAP312_WEB_TECHNOLOGIES_II
P. 32
Web Technologies-II
Notes Extreme Programming (XP). Its strong typing helps to prevent many programming errors that
are common in weakly typed languages.
A large part of the power of C# (as with other .NET languages), comes with the common .NET
Framework API, which provides a large set of classes, including ones for encryption, TCP/IP
socket programming, and graphics. Developers can thus write part of an application in C# and
another part in another .NET language (e.g. VB .NET), keeping the tools, library, and object-
oriented development model while only having to learn the new language syntax.
Because of the similarities between C# and the C family of languages, as well as Java, a developer
with a background in object-oriented languages like C++ may find C# structure and syntax
intuitive.
2.1 A Simple Web Page
To compile your first C# function, you will need of a .NET Framework SDK installed on your PC.
There are two .NET frameworks accessible: Microsoft’s and Mono’s
Microsoft
For Windows, the .Net Framework SDK can be downloaded from Microsoft’s .NET Framework
Developer Center. If the default Windows directory (the directory where Windows or WinNT
is installed) is C:\WINDOWS, the .Net Framework SDK installation places the Visual C# .NET
Compiler (csc) in the C:\WINDOWS\Microsoft.NET\Framework\v1.0.3705 directory for version
1.0, the C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322 directory for version 1.1, or the
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 directory for version 2.0.
Mono
For Windows, Linux, or other Operating Systems, an installer can be downloaded from the
Mono website.
For Linux, a good compiler is cscc which can be downloaded for free from the DotGNU Portable.
Net project page. The compiled programs can then be run with ilrun.
If you are working on Windows it is a good idea to add the path to the folders that contain
cs.exe or mcs.exe to the Path environment variable so that you do not need to type the full path
each time you want to compile.
It is entirely possible to write C#.NET programs with a simple text editor, but it should be noted
that this requires you to compile the code yourself. Microsoft offers a wide range of code editing
programs under the Visual Studio line that offer syntax highlighting as well as compiling and
debugging capabilities. Currently C#.NET can be compiled in Visual Studio 2002 and 2003 (only
supports the .NET Framework version 1.0 and 1.1) and Visual Studio 2005 (supports the .NET
Framework 2.0 and earlier versions with some tweaking).
The code below will demonstrate a C# program written in a simple text editor. Start by saving
the following code to a text file called hello.cs:
using System;
namespace MyConsoleApplication
{
class MyFirstClass
{
static void Main (string[] args)
{
26 LOVELY PROFESSIONAL UNIVERSITY