Вы находитесь на странице: 1из 44

An Introduction to .

NET Framework
The .NET Framework is a Microsoft's development platform. It offers to develop software applications. It was released by Microsoft Corporation in 2002. Later on, several improvements take place in .NET Framework, which makes it as much strong, advanced and more efficient platform for building different kinds of software applications. Why it is called as platform is, it acts as platform for multiple languages, tools and libraries. It offers visually stunning user experiences, which is mostly required today s competitive programming world. It offers much advanced security features never before. Supports dozens of languages like C#, VB.NET, VC++.NET, COBOL, Pascal, Python etc.

Features of .NET Framework


n Next Generation User Experiences:
.NET offers a Framework for building applications and high-fidelity experiences in Windows that blend together application UI, documents, and media content, while exploiting the full power of the computer. WPF (Windows Presentation

.NET 3.5 and Visual Studio 2008

Hour 6 - Page 1 of 44

Foundation) offers developers support for 2D and 3D graphics, hardware accelerated effects, scalability to different form factors, interactive data visualization, and superior content readability.

Seamless and Secured Environment:


Application security is a big deal these days; perhaps the most closely examined feature of any new application. .NET offers its best secured environment at run time. So that it is highly impossible to access the .NET application and its related data by the un-authorized users / hackers. The assembly (the compiled code of .NET framework) contains the security information like which categories of users or who can access the class or method. So that we can say that .NET Framework applications are much secured. The security can be improved in the ASP.NET Web Sites by Security models like Integrated Windows Authentication, Microsoft Passport Authentication, Forms Authentication, and Client Certificate authentication.

Multi Language Support:


.NET provides a multi-language development platform, so you can work in the programming language you prefer. The Common Language Runtime (A part of

.NET Framework) provides support for 3 Microsoft developed languages and several
other languages from other vendors.

Languages Supported by .NET Framework


Languages from Microsoft Visual C#.NET Visual Basic.NET Visual C++.NET APL, Cobol, Perl, Pascal, Component Pascal, Curriculum, Eiffel,

Languages vendors

from

other

.NET 3.5 and Visual Studio 2008

Hour 6 - Page 2 of 44

Forth, Fortran, Haskell, J#, Mercury, Mondrian, Oberon, Python, IronPython, RPG, Scheme, Small Talk, Standard ML

Flexible Data Access:


.NET Framework supports flexible accessibility of database data with ADO.NET (ActiveX Data Objects .NET). ADO.NET is a set of classes that expose data access services to the .NET programmer. ADO.NET provides a rich set of components for creating distributed, data-sharing applications. It is an integral part of the .NET Framework, providing access to relational, XML, and application data.

Modules of .NET
1. C#.NET (C Sharp.NET) (Language)
It is highly used .NET programming language, used by most of the .NET programmers. It borrows some programming features from C and some other programming features from C++ . In addition to these, it borrows few of the good features of java language. It is the object oriented programming language.

2. VB.NET (Visual Basic.NET) (Language)


It is the Microsoft s recommended language for beginners of windows programming.

.NET 3.5 and Visual Studio 2008

Hour 6 - Page 3 of 44

But in fact, it is used in very few of the projects in the real-time development world, because most of the programmers usually comes with C and C++ background; hence they feel comfortable with C# . It borrows some programming features from VB (Visual Basic) language. It is the object oriented programming language.

3. ASP.NET (Active Server Pages.NET)

(Web Technology)

It is the Microsoft s web technology. It is used for web sites development. It offers much attractive and user friendly user interfaces in the server side applications. It is the new version to another Microsoft s technology called ASP (Active Server Pages), which is a famous web technology before introducing ASP.NET. It requires HTML for web page designing. It requires a .NET language (like C#, VB.NET, VC++.NET etc.) for server side logic implementation.

4. ADO.NET (ActiveX Data Objects.NET)


It is the Microsoft s database technology.

(Database Technology)

It offers necessary programming libraries to access the local / server databases. It is the new version to another Microsoft s technology called ADO (ActiveX Data Objects), which is a famous database technology, used with VB, VC++ and ASP languages. It requires a .NET language (like C#, VB.NET, VC++.NET etc.) for logic implementation.

Applications of .NET

.NET 3.5 and Visual Studio 2008

Hour 6 - Page 4 of 44

Using .NET Framework, we offered to develop the following types of applications.

1. Console Applications
These applications contains similar user interface to the operating systems like MSDOS and UNIX. Known as C.U.I (Character User Interface) applications. These are similar to C/C++ applications. These are smaller in size. Doesn t contain any graphical features like mouse pointer, colors, fonts, buttons etc.

2. Windows Applications
These applications are designed similar to the Windows operating system. Known as G.U.I (Graphical User Interface) applications. Offers graphical features like mouse pointer, colors, fonts, buttons, text boxes etc.

.NET 3.5 and Visual Studio 2008

Hour 6 - Page 5 of 44

3. Windows Services
A Windows service is a long-running executable application. These can run only on windows platforms. These perform specific functions as background process. Doesn t contain user interface or doesn t require any user interaction. Windows services can be configured to start when the operating system is booted and run in the background as long as Windows is running, or they can be started manually when required. Examples: i. Windows Time. ii. Windows Audio. iii. Anti-Virus Security. iv. Database services like Sql Server, My Sql and Oracle etc. v. IIS State Services. vi. Battery Power Supply Status on Laptops.

.NET 3.5 and Visual Studio 2008

Hour 6 - Page 6 of 44

etc. To see the all the installed windows services on the system, click on Start Control Panel Administrative Tools Services .

4. Windows Mobile Applications


The Mobile applications can run on the small devices like Pocket PCs, Smart phones and mobile devices. Ex: Mobile based calculators, schedulers, database manipulation applications etc.

.NET 3.5 and Visual Studio 2008

Hour 6 - Page 7 of 44

5. Web Sites / Web Applications


These are most frequently used applications by every internet literature. In modern life every business (commercial) / educational / service oriented organizations are having their own web sites. Some other web sites are offering general purpose services that can be used by anybody like E-Mail, Search Engines, and Blogs etc. So, there is much demand for these applications in modern software development industry. In .NET Framework, the web sites can be developed using the technology called ASP.NET. Ex: i. http://www.yahoo.com/ ii. http://www.google.co.in/ iii. http://www.orkut.com/ iv. http://www.hotmail.com/

.NET 3.5 and Visual Studio 2008

Hour 6 - Page 8 of 44

6. Web Services
Web Services are simple and easy to understand. These can be developed using again ASP.NET. These are also known as web applications similar to web sites . But Web sites expose certain user interface (in the form of web pages) to the end-user; Web services expose a certain programming logic which can be accessed through another web site. Examples: i. Online shopping requires credit card authentication. ii. www.way2sms.com accesses the mail services of Yahoo and Gmail.

What we need to learn .NET


To get started with .NET Programming, the programmer must have previous knowledge in the following languages.

.NET 3.5 and Visual Studio 2008

Hour 6 - Page 9 of 44

C (For Procedural Programming Experience)

C++ (or) OOP Knowledge (For Object Oriented Programming Experience)

SQL (For db queries)

HTML (For web page designing)

Before .NET
Branches of Microsoft Programming:
In the late 1990s, Windows programming using the Microsoft platform had divided into a number of branches. n n n Most programmers were using Visual Basic (VB). Some other programmers were using Visual C++ (VC++) with MFC (Microsoft Foundational Classes). The remaining programmers were using C or C++ in a combination with raw Win32 API.

Difficulties and Limitations:


All of these technologies had their own problems and difficulties. n The raw Win32 API was not object-oriented, doesn t supports a full-pledged graphical application because of limited libraries.

.NET 3.5 and Visual Studio 2008

Hour 6 - Page 10 of 44

n n n

MFC was object-oriented, but was inconsistent and getting old and it is very much complex in actual coding. There is no a perfect platform independent language. There is no easier mobile based application development language.

Promises by Microsoft:
While introducing .NET Framework, Microsoft Corporation given a promise to the software industry to deliver a standard Framework which overcomes the old problems and along with following: n n n Multiple platforms: The system runs on a broad range of computers, from servers and desktop machines, smart phones and cell phones. Industry standards: The system uses industry standard communication protocols, such as XML, HTTP, SOAP, and WSDL. Security: The system can provide a much safer execution environment, which can t be hacked or robbed by others.

.NET Versions
.NET Framework Version Exact Version Number

Date of Release

Visual Studio

.NET Framework 1.0

1.0.3705.0

Feb 13, 2002

Visual Studio .NET

.NET Framework 1.1

1.1.4322.573

April 24, 2003

Visual Studio .NET 2003

.NET Framework 2.0

2.0.50727.42

November 17, 2005

Visual Studio 2005

.NET 3.5 and Visual Studio 2008

Hour 6 - Page 11 of 44

.NET Framework 3.0

3.0.4506.30

November 06, 2006

.NET Framework 3.5

3.5.21022.8

November 19, 2007

Visual Studio 2008

.NET Framework 4.0 (Beta)

October 19, 2009

Visual Studio 2010 (not yet released completely, but a beta version is available on internet)

Introducing Visual Studio


About Visual Studio:
n n Visual Studio is nothing but the Visual IDE (Integrated Development Environment), which is needed to development applications with .NET Framework. In simple, we can say like .NET Framework is something that is required to run the .NET applications and Visual Studio is something that is required to develop the .NET applications .

Visual Studio Versions:


n There are several versions in Visual Studio like Visual Studio 2002, Visual Studio 2003, Visual Studio 2005 and Visual Studio 2008 (as shown in the previous table).

Getting started with Visual Studio:


n To start with Visual Studio 2008 (the latest version till-to-date), click Start Programs Microsoft Visual Studio 2008 Microsoft Visual Studio 2008 .

.NET 3.5 and Visual Studio 2008

Hour 6 - Page 12 of 44

System Requirements of Visual Studio 2005


n Processor: n RAM: n OS: Microsoft Windows (2000 / XP / 2003 / Vista / 2008 / Windows 7) n Hard disk free space: Minimum: 192 MB Recommended: 256 MB / 512 MB (or above) Minimum: P-III Recommended: P-IV (or Higher)

.NET 3.5 and Visual Studio 2008

Hour 6 - Page 13 of 44

2.3 GB (on system drive ( C: ))

CD/DVD Drive: (For Installation)

Internet Connection (optional): (To get latest news from Microsoft s web site)

System Requirements of Visual Studio 2008

Processor: RAM: Minimum: 512 MB Recommended: 1 GB (or above) MS Windows (XP / 2003 / Vista / 2008 / Windows 7) Minimum: P-IV Recommended: Higher than P-IV

OS:

n n

Hard disk free space: n 4.2 GB (on system drive ( C: )) CD/DVD Drive (For Installation)

Internet Connection (optional) (To get latest news and updates from Microsoft s web site)

Advantages of .NET

.NET 3.5 and Visual Studio 2008

Hour 6 - Page 14 of 44

n n n n n n n n n n n n n n n n

Supports multiple languages like VC#, VB.NET, VC++.NET, VJ#.NET etc., so that the programmer can write the code in his/her interested language. Offers more secured environment never before. Offers flexible data access with ADO.NET Supports to develop windows services and web services, which are necessary to handle in the live projects in the modern programming world. Supports to develop applications for small devices like PDA s, smart phones, mobile phones etc. Offers platform independency , because it supports to run the .NET applications on other platforms like UNIX, LINUX and Solaris etc., with .NET Mono framework. Offers easier and faster UI design (with drag and drop technique), when compared with the languages like Java. Offers the best debugging tools in the industry, which makes the programmer to easily fix the bugs. Offers improved object oriented programming features like properties, sealed classes, inner classes, delegates, enumerations, collections, interfaces, generics etc. Offers to share and reuse the code among multiple applications very easily, with the concept of Assemblies . Offers to write queries in the programming code itself, using the newly added feature called LINQ (Language Integrated Query). This is newly added feature in .NET 3.5. Offers faster and easier Deployment features, to generate Installer packages for installing the .NET application on the client systems. Offers to create multiple threads and also to manage them for creating Multi-Threaded Applications. Offers XML support and interaction, which is mostly required in the modern application development environment. Supports to create user defined graphics like lines, rectangles, bars, circles etc., very easily using GDI+ (Graphics Device Interface) concepts. Offers a new and attractive feature called WPF (Windows Presentation Foundation), which is built on DirectX and which enables the programmer to create 2-D and 3-D graphics, animation, games, audio and view players etc. This is newly added feature in .NET 3.5.

.NET 3.5 and Visual Studio 2008

Hour 6 - Page 15 of 44

Offers another prestigious feature called WCF (Windows Communication Foundation), which integrates the network programming related libraries of .NET like .NET Remoting, SOAP enabled web services and message queues etc., which helps the programmer to develop service and network oriented applications using .NET. This is newly added feature in .NET 3.5.

Support for the most recent web technology called AJAX (Asynchronous JavaScript and XML) along with ASP.NET. As a result of AJAX, the developer can produce newer generation user experiences on the web. Ex: www.orkut.com.

.NET (vs) Java


Microsoft s .NET and SUN s Java are strong competitors.

Similarities
Sl. No 1 2 3 4 5 6 7 8 9 10 11 .NET and Java Both of these support to develop console applications, windows applications, web sites, web services etc. Both use their own intermediate language. Java calls it as byte code and .NET calls it as MSIL . Both are Object oriented programming languages. Both support Remoting. Both supports multi-threading. Both are platform independent. Both support web related languages like Java Script, XML, CSS etc. Both support the recent web development technology like AJAX. Both support Garbage collection , which automatically clears the un-used memory. Both support to develop the applications for small devices like PDA s, mobile phones, smart phones etc. Both offer better security features in their own style.

Differences
Sl. No 1 2 3 .NET It is cost effective. Costs more than $700 (nearly Rs. 35,000) Supports Language Independency (supports multiple languages) Offers IDE as Visual Studio by Java It is open source product, which can be freely downloaded on the Internet. Doesn t offer multiple languages Doesn t offer any IDE. But other IDE s by

.NET 3.5 and Visual Studio 2008

Hour 6 - Page 16 of 44

4 5 6

Microsoft. Offers easiest and fastest application development, which indirectly reduces the cost of the software. Designing the UI is very much easy with Drag and Drop technique. AJAX is implementation is much easy.

other vendors such as Eclipse etc. Requires much time for the application development, which indirectly increases the cost of the software. UI Design requires much programmer s effort and stress. AJAX is implementation is much time taking process, requires much code to write.

.NET FRAMEWORK in-depth


.NET Framework Types:
The .NET Framework is available in 4 different types: n n n n .NET Framework: This is the general version, required to run .NET applications on Windows operating system. .NET Mono Framework: This is required to run .NET applications on other operating systems like UNIX, LINUX and Solaris etc. .NET Compact Framework: This is required to run .NET applications on other devices like PDA (Personal Digital Assistants), Mobile phones and Smart phones. .NET Micro Framework: This is very much smaller in memory size. This is designed to run .NET applications on the like Mobile phones and Smart phones having small memory capacity.

Components of .NET Framework


The .NET Framework is simply a collection of two components. 1. FCL (.NET Framework Class Library) 2. CLR (Common Language Runtime)

.NET 3.5 and Visual Studio 2008

Hour 6 - Page 17 of 44

Components of .NET Framework


The .NET Framework is simply a collection of two components. 3. FCL (.NET Framework Class Library) 4. CLR (Common Language Runtime) You can see the .NET Framework Architecture in the following diagram.

1. .NET Framework Class Library (FCL)


n The .NET Framework class library contains the necessary library classes that are needed for development of different types of .NET applications like Console applications, Windows applications, Windows services, ASP.NET Web sites, ASP.NET Web Services, Windows Communication Foundation (WCF) applications and Windows Presentation Foundation (WPF) applications. n The library s classes are organized using a hierarchy of namespaces.

.NET 3.5 and Visual Studio 2008

Hour 6 - Page 18 of 44

n n

A namespace is nothing but a collection of classes. For example, all the classes for performing I/O operations are located in the System.IO namespace.

2. Common Language Run Time (CLR)


n The Common Language Runtime (CLR) is the agent that manages your .NET applications at execution time. In other words, CLR is the completely responsible component of .NET Framework that is responsible to manage the .NET applications at run time. n n n In other words, The Common Language Runtime (CLR) is the virtual machine in the .NET Framework. It provides core services such as memory management, thread management, exception handling, security and resource management. A .NET application is compiled into a bytecode format known as MSIL (Microsoft Intermediate Language). The MSIL bytecode allows .NET applications to be portable (at least theoretically) to other platforms because the application is compiled to native code only during runtime. n During execution, the CLR s JIT (just - in - time) compiles the bytecode into the processor s native code and executes the application.

Assemblies and Microsoft Intermediate Language (MSIL)


n In .NET, when an application is compiled, into a bytecode called MSIL. That MSIL code is stored in an assembly. The assembly is contained in one or more PE (portable executable) files and may end with an EXE or DLL extension. n The assembly contents are: Byte code The code in MSIL language. Information about the users / user types, who can Security Information access the assembly.

.NET 3.5 and Visual Studio 2008

Hour 6 - Page 19 of 44

Manifest Versioning

Information about the assembly, such as identification, name, The version number of an assembly. Information that describes the types and methods of the assembly.

version, and so on. Metadata

Types of Assemblies
n n Private Assemblies: The private assemblies are simple types. An assembly that can be used only within a software application is called as Private assembly . Shared Assemblies: An assembly that can be used by one or more software applications is called as Shared Assemblies .

Example:
To get a better idea of a MSIL file and its content, take a look at the following example, which has two console applications. One is written in C# and the other is written in VB.NET.

The following C# code displays the console window:

Hello, World

message in the

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace HelloWorldCS { class Program { static void Main(string[] args) { Console.WriteLine( Hello, World! ); Console.ReadLine(); } } }

The following VB.NET code displays the Hello, World message in the console window:
Module Module1 Sub Main() Console.WriteLine( Hello, World! ) Console.ReadLine()

.NET 3.5 and Visual Studio 2008


End Sub

Hour 6 - Page 20 of 44

The Main method of the C# MSIL looks like this:


.method private hidebysig static void Main(string[] args) cil managed { .entrypoint // Code size 19 (0x13) .maxstack 8 IL_0000: nop IL_0001: ldstr Hello, World! IL_0006: call void [mscorlib]System.Console::WriteLine(string) IL_000b: nop IL_000c: call string [mscorlib]System.Console::ReadLine() IL_0011: pop IL_0012: ret } // end of method Program::Main

The Main method of the VB.NET MSIL looks like this:


.method public static void Main() cil managed { .entrypoint .custom instance void [mscorlib]System.STAThreadAttribute::.ctor() = ( 01 00 00 00 ) // Code size 20 (0x14) .maxstack 8 IL_0000: nop IL_0001: ldstr Hello, World! IL_0006: call void [mscorlib]System.Console::WriteLine(string) IL_000b: nop IL_000c: call string [mscorlib]System.Console::ReadLine() IL_0011: pop IL_0012: nop IL_0013: ret } // end of method Module1::Main

.NET 3.5 and Visual Studio 2008

Hour 6 - Page 21 of 44

Conclusion: The Main method of the VB.NET MSIL looks very similar to that of the C#.NET s MSIL program. The important thing to note here is that regardless of the language you use to develop your .NET applications, all .NET applications are compiled to the MSIL bytecode as this example shows. Note: MSIL can also be called as IL (Intermediate Language) and CIL (Common Intermediate Language).

The RTE (Run Time Environment) of an .NET Application


Code in another .NET Language

Code in C#.NET

Code in VB.NET

C#.NET Compiler

VB.NET Compiler

Another Compiler

MSIL Code

Just-in Time Compiler

Common Language Run Time

Native Machine Code

Execute .NET 3.5 and Visual Studio 2008

Hour 6 - Page 22 of 44

.NET 3.5 and Visual Studio 2008

Hour 6 - Page 23 of 44

Components of CLR
The CLR contains the following components. n n n n n Security Manager / Code safety verifier JIT Compiler Memory Manager Garbage Collector Exception Manager

3.

Security Manager / Code Safety Verifier


n n n This is the initial and most component of CLR. Application security is much more important issues today. If you analyze this in-depth, we have 3 types of security support by .NET Framework. A. Evidence Based Security (EBS): This security feature is meant for protecting entire assembly not to be accessed by un-authorized users. The Security Manager component first checks privileges of the current user that the user is allowed to access the assembly or not, based on the evidence . The evidence is nothing but the information about the security permissions related to the assembly, that resides with in the assembly. B. Code Access Security (CAS): This verifies whether the current user is allowed to perform the actions written in the MSIL code. For example, accessing the file system, event log, printing, remote or network access etc.

.NET 3.5 and Visual Studio 2008

Hour 6 - Page 24 of 44

4.

JIT Compiler
n n As you seen in the diagram of RTE previously, the JIT compiler is responsible for compiling the MSIL code into the Native code . The native code is directly understandable by the system hardware.

5.

Memory Manager
n The Memory Manager component of CLR, allocates necessary memory for the variables and objects that are to be used by the application.

6.

Garbage Collector
n n This component of CLR de-allocates or cleans-up the un-necessary memory of the application, after usage automatically. Instead, in older languages such as C/C++ this kind of component is not available so that the programmer should free-up the memory explicitly using some code.

7.

Exception Manager
n n n An exception means Run time error . This component redirect the processor to execute the catch block or finally block, whenever an exception is occurred at run time. We can learn how to write these catch and finally blocks in C#.NET and VB.NET languages later.

Naming Convention 1. Namespace, Classes and Methods:


Each world in the name space should be started with upper case character. Ex: WebControls, Threading, OracleClient, InitializeComponent() etc.

2. Variables and objects:


This is programmer s choice. You can maintain all the characters in lower case (or) you can also maintain the naming convention recommended for namespaces. Ex: i, abc, Abc, AbcXyz etc.

.NET 3.5 and Visual Studio 2008

Hour 6 - Page 25 of 44

The .NET Framework Class Library (FCL) Architecture


The .NET Framework Class Library contains the following namespaces. Note: A namespace is a collection of few classes or namespaces. The inner namespaces, contained by another namespace is called as sub namespace . The most frequently used namespaces of FCL are listed here.

System

Windows

Web

Drawing

Data

Xml

Linq

Threading

IO

Tex

Forms

UI

Printing

OleDb

SqlClient

OracleClient

HtmlControls

WebControls

Getting Started with Visual Studio 2008


I) Opening Visual Studio 2008
n n Click on Start 2008 . The following screen will be opened. Programs Microsoft Visual Studio 2008 Microsoft Visual Studio

.NET 3.5 and Visual Studio 2008

Hour 1 - Page 26 of 44

n n

Initially, the Visual Studio 2008 will be opened along with Start Page . The start page is nothing but the welcome page, which contains Logo: A logo of Microsoft Visual Studio 2008 on the top of the start page. Recent Projects: List of most recently opened projects. If you click on any one, the project will be opened immediately. Getting started: Headlines of visual studio help for .NET beginners. If you click on any one head line, online help will be opened (if Internet connection is available). Visual Studio Headlines: The headlines about the latest releases of .NET and Visual Studio versions, updates, beta versions, service packs etc. If you click on any one head line, online help will be opened (if Internet connection is available). MSDN - Visual Studio: Most recent headlines of visual studio help from MSDN (Microsoft Developer Network). If you click on any one head line, online help will be opened (if Internet connection is available).

.NET 3.5 and Visual Studio 2008

Hour 1 - Page 27 of 44

II) The Visual Studio 2008 Basics


To start programming with Visual Studio, you should know some common terminology that is used most frequently in Visual Studio. n Project: An application developed in Visual Studio. That may be of different types such as Console application, Windows application, Windows Service, Web site etc. n Solution: Collection of one or more projects. Initially, in a solution, one project will be placed. Later, you can add other projects to it. n n Build: Compilation of entire .NET Project. Class: A collection of data members and methods (member functions). Ex:

class class1 { int mydatamember; private void mymethod() { } }


n Namespace: It s nothing but a collection of classes. It may also contain sub namespaces. A project may require implementing at least one or more classes. In .NET, all of the classes related one application should be defined with a user defined namespace. Ex:

namespace MyApplication { class class1 { } class class2 .NET 3.5 and Visual Studio 2008 { } }

Hour 1 - Page 28 of 44

III) Creating a new project


To create a new project in Visual Studio, follow the steps given below. n n Open Microsoft Visual Studio 2008. Click on File New Project .

In the New Project dialog box, the left side panel displays the list of .NET languages like Visual C#

.NET 3.5 and Visual Studio 2008

Hour 1 - Page 29 of 44

Visual Basic Visual C++ etc. The right side panel displays the list of project templates like Windows Forms Applications Class Library ASP.NET Web Application ASP.NET Web Service Application WPF Application WPF Browser Application Console Application WCF Service Application Windows Forms Control Library

Select the appropriate language and required project template. For example select Visual C# and Windows Forms Application .

.NET 3.5 and Visual Studio 2008

Hour 1 - Page 30 of 44

Provide the following details: n n n Name: Specifies the name of the project. Ex: WindowsFormsApplication1. Location: Specifies the path, in which the project is to be stored. Solution Name: The actual name of the solution. (By default the solution will be created with one project, later you can add other projects to this solution if needed).

Click on OK to confirm. Then the new project will be created.

In the above screen, you can see an empty form created automatically, named as Form1 .

IV) Project Directory Structure


When we create a new project, some directory structure will be created automatically by following the below specified rules. n Each solution will be created as a folder.

.NET 3.5 and Visual Studio 2008

Hour 1 - Page 31 of 44

n n n

Each project will be created as a folder, and placed in the solution folder. All the files related to the project, will be placed in the project folder. The information about the solution members will be saved in a file called Solution file and it will be placed in the solution folder. When we double click on it, that solution will be opened in Visual Studio. The file extension of the solution file is .sln .

In the same way, the information about the project members will be saved in the Project file and it will be placed in the project folder. When we double click on it, that project will be opened in Visual Studio.

You can observe the project directory structure according to our previous example. Note: First, recollect the project name, project location and solution name from previous example.

Project Folder
Solution Folder:

Solution File

.NET 3.5 and Visual Studio 2008

Hour 1 - Page 32 of 44

.NET 3.5 and Visual Studio 2008

Hour 1 - Page 33 of 44

Project Folder:

bin: This folder contains the EXE file after compiling the project. obj: This folder contains the temporary files of the project, while compilation. Properties: This folder contains necessary files that contain information about the settings and resources related to the project. WindowsFormsApplication1 (Project File): This file contains the information about all the files related to the project; When you double click on it, the project will be opened in Visual Studio. Form1.cs: This file contains the executable code of Form1 . Form1.Designer.cs: This file contains the code related to the design of Form1. Program.cs: This file contains the code of Program class with Main() method.

.NET 3.5 and Visual Studio 2008

Hour 1 - Page 34 of 44

Components of Visual Studio IDE


In this section, we make a closer look to the IDE offered by Visual Studio.

Menu Bar

Tool Bars

Tabs

Form Designer

Solution Explorer

Toolbox

Properties window

1) Menu Bar: This bar contains the available menus in Visual Studio like File , Edit , View and Project etc. 2) Tool Bars: There are several toolbars in Visual Studio, which contain frequently used options in Visual Studio. 3) Tabs: Displays tabs; just click to open required tab. 4) Form designer: Used to view and edit the visual design of the form.

.NET 3.5 and Visual Studio 2008

Hour 1 - Page 35 of 44

5) Code Window: This is where you write actual programming of your application. You can switch to this view, by right click on the form designer and choosing View Code (or) by pressing F7 key on the keyboard.

6) Solution Explorer: Explores the information about the solution and its members. 7) Properties: Displays the available properties and values for the selected solution, project, form or control; and also allows to change the property values. 8) Other: In addition to the above specified IDE components, some other components are also available docked at the bottom area of Visual Studio window like Output , Error List , Command window , Immediate window , Breakpoints . We discuss about these components whenever required, in upcoming chapters later.

V) Creating Console Applications


The console applications are the project types, recommended for the .NET programming beginners, where you can learn the language features better.

.NET 3.5 and Visual Studio 2008

Hour 1 - Page 36 of 44

n n

In Microsoft Visual Studio 2008, click on File Application .

New

Project .

Select the language as Visual C# and select the project template as Console

Then enter the project name and location (with your choice) and click on OK.

.NET 3.5 and Visual Studio 2008

Hour 1 - Page 37 of 44

C#.NET
Overview
n n n n n n It s a programming language, offered by .NET Framework. It is recommended for both .NET programming beginners and .NET professionals. This is the mostly used languages used by most of the IT companies today. It derives some programming features from C and C++ also. It is the object oriented programming language. The programmer, having knowledge in C and C++ can easily understand the programming in C#.

.NET 3.5 and Visual Studio 2008

Hour 1 - Page 38 of 44

File Extensions in C#
n n Project File Extension: .csproj (means C Sharp Project) Code File Extension: .cs (means C Sharp)

Sample Application Development in C#


n n n n Launch Visual Studio 2008. Create a new Console Application with Visual C# language. It generates an empty Program class, with Main() method. Type a simple program as follows:

.NET 3.5 and Visual Studio 2008

Hour 1 - Page 39 of 44

Application 1: A simple C# program

To run the application, simply press F5 key on the keyboard. Then the application will be executed and output will be as follows.

.NET 3.5 and Visual Studio 2008

Hour 1 - Page 40 of 44

A closer look at the syntax


Importing section Namespace Declaration Class Declaration

Main() method 1. Importing section:


This section contains importing statements that are used to import (include or link) the .NET Framework Class Library (FCL). This is most similar to the include statements in C language. Syn: using namespace; Note: If the required namespace is a member of another namespace, we have specify the parent and child namespaces separated with . (dot). Ex:

.NET 3.5 and Visual Studio 2008

Hour 1 - Page 41 of 44

using System; using System.IO; using System.Data; etc.

2. Namespace declaration:
Here, a user define namespace is to be declared. Rule: In .NET applications, all the classes related to the project should be declared in one namespace. Syn: namespace namespacename { } Generally, the namespace name will be same as Project name.

2. Class declaration:
This is to declare the startup class of the project. In every .NET application (like Console and Windows Application), there should a startup class. In these applications, the startup class name should be Program . You can t change it. A startup class nothing but a class, which contains Main() method. Syn: class classname { }

3. Main() method:
As you know already in C/C++ languages, the Main() method is the Starting Execution Point of the application. When the application is executed, the Main() method will be executed first. This method contains the main logic of the application.

.NET 3.5 and Visual Studio 2008

Hour 1 - Page 42 of 44

.NET 3.5 and Visual Studio 2008

Hour 1 - Page 43 of 44

Syn:

Specifies that Main() is a static method; to enable JIT, to directly call Main() method directly, without creating an instance of Program class.

Means no return value Receives arguments sent to the Main() method in a string array format.

.NET 3.5 and Visual Studio 2008

Hour 1 - Page 44 of 44

Вам также может понравиться