Dotnet Classes

Embed Size (px)

Citation preview

  • 8/2/2019 Dotnet Classes

    1/44

    .NET 3.5 and Visual Studio 2008 Hour 6 - Page 1 of 44

    AAnn IInnttrroodduuccttiioonn ttoo ..NNEETT FFrraammeewwoorrkk

    The .NET Frameworkis 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 andlibraries.

    It offers visually stunning user experiences, which is mostly required todays competitiveprogramming 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

  • 8/2/2019 Dotnet Classes

    2/44

    .NET 3.5 and Visual Studio 2008 Hour 6 - Page 2 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.

    n 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 atrun 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 thesecurity 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.

    n 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#.NETVisual Basic.NET

    Visual C++.NET

    Languages from other

    vendors

    APL,Cobol,Perl,Pascal,Component Pascal,Curriculum,Eiffel,

  • 8/2/2019 Dotnet Classes

    3/44

    .NET 3.5 and Visual Studio 2008 Hour 6 - Page 3 of 44

    Forth,Fortran,Haskell,

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

    n 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 .NETprogrammers.

    It borrows some programming features from C and some otherprogramming features from C++. In addition to these, it borrows few ofthe good features of java language.

    It is the object oriented programming language.

    2. VB.NET (Visual Basic.NET) (Language) It is the Microsofts recommended

    language for beginners of windowsprogramming.

  • 8/2/2019 Dotnet Classes

    4/44

    .NET 3.5 and Visual Studio 2008 Hour 6 - Page 4 of 44

    But in fact, it is used in very few of the projects in the real-time developmentworld, 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 Microsofts web technology. It is used for web sites development.

    It offers much attractive and user friendlyuser interfaces in the server sideapplications.

    It is the new version to another Microsofts technology called ASP (ActiveServer Pages), which is a famous web technology before introducingASP.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) (Database Technology)It is the Microsofts database technology.

    It offers necessary programming libraries to accessthe local / server databases.

    It is the new version to another Microsoftstechnology called ADO (ActiveX Data Objects),which is a famous database technology, used withVB, VC++ and ASP languages.

    It requires a .NET language (like C#, VB.NET, VC++.NET etc.) for logicimplementation.

    AApppplliiccaattiioonnss ooff..NNEETT

  • 8/2/2019 Dotnet Classes

    5/44

    .NET 3.5 and Visual Studio 2008 Hour 6 - Page 5 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 MS-

    DOS and UNIX.

    Known as C.U.I (Character User Interface) applications. These are similar to C/C++ applications. These are smaller in size. Doesnt 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.

  • 8/2/2019 Dotnet Classes

    6/44

    .NET 3.5 and Visual Studio 2008 Hour 6 - Page 6 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. Doesnt contain user interface or doesnt 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 bestarted 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.

    http://en.wikipedia.org/wiki/Booting
  • 8/2/2019 Dotnet Classes

    7/44

    .NET 3.5 and Visual Studio 2008 Hour 6 - Page 7 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, Smartphones and mobile devices.

    Ex: Mobile based calculators, schedulers,database manipulation applications etc.

  • 8/2/2019 Dotnet Classes

    8/44

    .NET 3.5 and Visual Studio 2008 Hour 6 - Page 8 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 byanybody like E-Mail, Search Engines, and Blogs etc.

    So, there is much demand for these applications in modern software developmentindustry.

    In .NET Framework, the web sites can be developed using the technology calledASP.NET.

    Ex:i. http://www.yahoo.com/ii. http://www.google.co.in/iii. http://www.orkut.com/iv. http://www.hotmail.com/

    http://www.yahoo.com/http://www.yahoo.com/http://www.google.co.in/http://www.google.co.in/http://www.orkut.com/http://www.orkut.com/http://www.hotmail.com/http://www.hotmail.com/http://www.hotmail.com/http://www.orkut.com/http://www.google.co.in/http://www.yahoo.com/
  • 8/2/2019 Dotnet Classes

    9/44

    .NET 3.5 and Visual Studio 2008 Hour 6 - Page 9 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 sitesexpose certain user interface (in the form of web pages) to the end-user; Webservices expose a certain programming logic which can be accessed throughanother web site.

    Examples:i. Online shopping requires credit card authentication.ii. www.way2sms.comaccesses the mail services of Yahoo and Gmail.

    WWhhaatt wwee nneeeedd ttoo lleeaarrnn ..NNEETT

    To get started with .NET Programming, the programmer must have

    previous knowledge in the following languages.

    http://www.way2sms.com/http://www.way2sms.com/http://www.way2sms.com/
  • 8/2/2019 Dotnet Classes

    10/44

    .NET 3.5 and Visual Studio 2008 Hour 6 - Page 10 of 44

    n C(For Procedural Programming Experience)

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

    n SQL(For db queries)

    n HTML(For web page designing)

    BBeeffoorree ..NNEETT

    Branches of Microsoft Programming:

    In the late 1990s, Windows programming using the Microsoft platform had divided into a

    number of branches.

    n Most programmers were using Visual Basic (VB).n Some other programmers were using Visual C++ (VC++) with MFC (Microsoft

    Foundational Classes).

    n The remaining programmers were using C or C++ in a combination with raw Win32API.

    Difficulties and Limitations:

    All of these technologies had their own problems and difficulties.

    n The raw Win32 API was not object-oriented, doesnt supports a full-pledged graphicalapplication because of limited libraries.

  • 8/2/2019 Dotnet Classes

    11/44

    .NET 3.5 and Visual Studio 2008 Hour 6 - Page 11 of 44

    n MFC was object-oriented, but was inconsistent and getting old and it is very muchcomplex in actual coding.

    n There is no a perfect platform independent language.n There is no easier mobile based application development language.

    PPrroommiisseess bbyy MMiiccrroossoofftt::

    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 Multiple platforms: The system runs on a broad range of computers, from servers anddesktop machines, smart phones and cell phones.

    n Industry standards: The system uses industry standard communication protocols,such as XML, HTTP, SOAP, and WSDL.

    n Security: The system can provide a much safer execution environment, which cant behacked or robbed by others.

    ..NNEETT VVeerrssiioonnss

    .NET FrameworkVersion

    Exact VersionNumber

    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

  • 8/2/2019 Dotnet Classes

    12/44

    .NET 3.5 and Visual Studio 2008 Hour 6 - Page 12 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 yetreleased completely, but abeta version is available oninternet)

    IInnttrroodduucciinngg VViissuuaall SSttuuddiioo

    About Visual Studio:

    n Visual Studio is nothing but the Visual IDE (Integrated DevelopmentEnvironment), which is needed to development applications with .NET Framework.

    n 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 Studio2003, 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 ProgramsMicrosoft Visual Studio 2008Microsoft Visual Studio 2008.

  • 8/2/2019 Dotnet Classes

    13/44

    .NET 3.5 and Visual Studio 2008 Hour 6 - Page 13 of 44

    SSyysstteemm RReeqquuiirreemmeennttss ooffVViissuuaall SSttuuddiioo 22000055

    n Processor: Minimum: P-III Recommended: P-IV (or Higher)

    n RAM: Minimum: 192 MB Recommended: 256 MB / 512 MB (or above)

    n OS: Microsoft Windows

    (2000 / XP / 2003 / Vista / 2008 / Windows 7)

    n Hard disk free space:

  • 8/2/2019 Dotnet Classes

    14/44

    .NET 3.5 and Visual Studio 2008 Hour 6 - Page 14 of 44

    2.3 GB (on system drive ( C: ))n CD/DVD Drive:

    (For Installation)

    n Internet Connection (optional):(To get latest news from Microsofts web site)

    SSyysstteemm RReeqquuiirreemmeennttss ooffVViissuuaall SSttuuddiioo 22000088

    n Processor: Minimum: P-IV Recommended: Higher than P-IV

    n RAM: Minimum: 512 MB Recommended: 1 GB (or above)

    n OS: MS Windows

    (XP / 2003 / Vista / 2008 / Windows 7)

    n Hard disk free space:n 4.2 GB (on system drive ( C: ))

    n CD/DVD Drive(For Installation)

    n Internet Connection (optional)(To get latest news and updates from Microsofts web site)

    AAddvvaannttaaggeess ooff..NNEETT

  • 8/2/2019 Dotnet Classes

    15/44

    .NET 3.5 and Visual Studio 2008 Hour 6 - Page 15 of 44

    n Supports multiple languages like VC#, VB.NET, VC++.NET, VJ#.NET etc., so that theprogrammer can write the code in his/her interested language.

    n Offers more secured environment never before.n Offers flexible data access with ADO.NETn Supports to develop windows services and web services, which are necessary to

    handle in the live projects in the modern programming world.

    n Supports to develop applications for small devices like PDAs, smart phones, mobilephones etc.

    n Offers platform independency, because it supports to run the .NET applications onother platforms like UNIX, LINUX and Solaris etc., with .NETMono framework.

    n Offers easier and faster UI design (with drag and drop technique), when compared withthe languages like Java.

    n Offers the best debugging tools in the industry, which makes the programmer to easilyfix the bugs.

    n Offers improved object oriented programming features like properties, sealedclasses, inner classes, delegates, enumerations, collections, interfaces, generics etc.

    n Offers to share and reuse the code among multiple applications very easily, with theconcept ofAssemblies.

    n Offers to write queries in the programming code itself, using the newly added featurecalled LINQ (Language Integrated Query). This is newly added feature in .NET 3.5.

    n Offers faster and easier Deployment features, to generate Installer packages forinstalling the .NET application on the client systems.

    n Offers to create multiple threads and also to manage them for creating Multi-ThreadedApplications.

    n Offers XML support and interaction, which is mostly required in the modern applicationdevelopment environment.

    n Supports to create user defined graphics like lines, rectangles, bars, circles etc., veryeasily using GDI+ (Graphics Device Interface) concepts.

    n Offers a new and attractive feature called WPF (Windows PresentationFoundation), 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.

  • 8/2/2019 Dotnet Classes

    16/44

    .NET 3.5 and Visual Studio 2008 Hour 6 - Page 16 of 44

    n 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 todevelop service and network oriented applications using .NET. This is newly added

    feature in .NET 3.5.

    n Support for the most recent web technology called AJAX (Asynchronous JavaScript andXML) along with ASP.NET. As a result of AJAX, the developer can produce newer

    generation user experiences on the web. Ex: www.orkut.com.

    .

    .NN

    EETT

    ((vvss))

    JJ

    aavvaa

    Microsofts .NET and SUNs Java are strong competitors.

    Similarities

    Sl.No

    .NET and Java

    1Both of these support to develop console applications, windows applications, websites, web services etc.

    2Both use their own intermediate language. Java calls it as byte code and .NETcalls it as MSIL.

    3 Both are Object oriented programming languages.

    4 Both support Remoting.

    5 Both supports multi-threading.

    6 Both are platform independent.

    7 Both support web related languages like Java Script, XML, CSS etc.

    8 Both support the recent web development technology like AJAX.

    9Both support Garbage collection, which automatically clears the un-usedmemory.

    10Both support to develop the applications for small devices like PDAs, mobilephones, smart phones etc.

    11 Both offer better security features in their own style.

    Differences

    Sl.No

    .NET Java

    1It is cost effective. Costs more than$700 (nearly Rs. 35,000)

    It is open source product, which can befreely downloaded on the Internet.

    2Supports Language Independency(supports multiple languages)

    Doesnt offer multiple languages

    3 Offers IDE as Visual Studio by Doesnt offer any IDE. But other IDEs by

    http://www.orkut.com/http://www.orkut.com/
  • 8/2/2019 Dotnet Classes

    17/44

    .NET 3.5 and Visual Studio 2008 Hour 6 - Page 17 of 44

    Microsoft. other vendors such as Eclipse etc.

    4Offers easiest and fastest applicationdevelopment, which indirectly reduces

    the cost of the software.

    Requires much time for the applicationdevelopment, which indirectly increases

    the cost of the software.

    5Designing the UI is very much easywith Drag and Drop technique.

    UI Design requires much programmerseffort and stress.

    6 AJAX is implementation is much easy. AJAX is implementation is much timetaking process, requires much code towrite.

    ..NNEETT FFRRAAMMEEWWOORRKK iinn--ddeepptthh

    ..NNEETT FFrraammeewwoorrkkTTyyppeess::

    The .NET Frameworkis available in 4 different types:

    n .NET Framework: This is the general version, required to run .NET applications onWindows operating system.

    n .NET Mono Framework: This is required to run .NET applications on other operatingsystems like UNIX, LINUX and Solaris etc.

    n .NET Compact Framework: This is required to run .NET applications on other deviceslike PDA (Personal Digital Assistants), Mobile phones and Smart phones.

    n .NET Micro Framework: This isvery much smaller in memory size. This is designed torun .NET applications on the like Mobile phones and Smart phones having small memory

    capacity.

    CCoommppoonneennttss ooff..NNEETT FFrraammeewwoorrkk

    The .NET Frameworkis simply a collection of two components.

    1. FCL (.NET Framework Class Library)2. CLR (Common Language Runtime)

  • 8/2/2019 Dotnet Classes

    18/44

    .NET 3.5 and Visual Studio 2008 Hour 6 - Page 18 of 44

    CCoommppoonneennttss ooff..NNEETT FFrraammeewwoorrkk

    The .NET Frameworkis 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.

    11.. ..NNEETT FFrraammeewwoorrkkCCllaassss LLiibbrraarryy ((FFCCLL))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 librarys classes are organized using a hierarchy of namespaces.

  • 8/2/2019 Dotnet Classes

    19/44

    .NET 3.5 and Visual Studio 2008 Hour 6 - Page 19 of 44

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

    System.IO namespace.

    22.. CCoommmmoonn LLaanngguuaaggee RRuunn TTiimmee ((CCLLRR))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 In other words, The Common Language Runtime (CLR) is the virtual machine in the.NET Framework.

    n It provides core services such as memory management, thread management,exception handling, security and resource management.

    n A .NET application is compiled into a bytecode format known as MSIL (MicrosoftIntermediate 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.

    nDuring execution, the CLR

    s JIT (just - in - time) compiles the bytecode into the

    processors native code and executes the application.

    AAsssseemmbblliieess aanndd MMiiccrroossoofftt IInntteerrmmeeddiiaattee LLaanngguuaaggee ((MMSSIILL))

    n In .NET, when an application is compiled, into a bytecode called MSIL. That MSIL codeis 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. Security Information Information about the users / user types, who can

    access the assembly.

  • 8/2/2019 Dotnet Classes

    20/44

    .NET 3.5 and Visual Studio 2008 Hour 6 - Page 20 of 44

    Manifest Information about the assembly, such as identification, name,version, and so on.

    Versioning The version number of an assembly. Metadata Information that describes the types and methods of the assembly.

    TTyyppeess ooffAAsssseemmbblliieess

    n Private Assemblies: The private assemblies are simple types. An assembly that canbe used only within a software application is called as Private assembly.

    n Shared Assemblies: An assembly that can be used by one or more softwareapplications 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 Hello, World message in theconsole window:

    The following VB.NET code displays the Hello, World message in the

    console window:

    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();

    }}

    }

    Module Module1

    Sub Main()

    Console.WriteLine(Hello, World!)

    Console.ReadLine()End Sub

  • 8/2/2019 Dotnet Classes

    21/44

    .NET 3.5 and Visual Studio 2008 Hour 6 - Page 21 of 44

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

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

    .method private hidebysig static void Main(string[] args) cil managed{

    .entrypoint

    // Code size 19 (0x13).maxstack 8IL_0000: nopIL_0001: ldstr Hello, World!IL_0006: call void [mscorlib]System.Console::WriteLine(string)IL_000b: nopIL_000c: call string [mscorlib]System.Console::ReadLine()IL_0011: popIL_0012: ret

    } // end of method Program::Main

    .method public static void Main() cil managed{

    .entrypoint

    .custom instance void [mscorlib]System.STAThreadAttribute::.ctor() = ( 01 0000 00 )// Code size 20 (0x14).maxstack 8IL_0000: nopIL_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: popIL_0012: nopIL_0013: ret

    } // end of method Module1::Main

  • 8/2/2019 Dotnet Classes

    22/44

    .NET 3.5 and Visual Studio 2008 Hour 6 - Page 22 of 44

    Conclusion: The Main method of the VB.NET MSIL looks very similar to that of the C#.NETs

    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).

    TThhee RRTTEE ((RRuunn TTiimmee EEnnvviirroonnmmeenntt)) ooffaann ..NNEETT AApppplliiccaattiioonn

    Code in C#.NET Code in VB.NET Code in another .NETLanguage

    Just-in Time

    Compiler

    VB.NET Compiler Another Compiler

    MSIL Code

    Common Language

    Run Time

    C#.NET Compiler

    Native Machine Code

    Execute

  • 8/2/2019 Dotnet Classes

    23/44

    .NET 3.5 and Visual Studio 2008 Hour 6 - Page 23 of 44

  • 8/2/2019 Dotnet Classes

    24/44

    .NET 3.5 and Visual Studio 2008 Hour 6 - Page 24 of 44

    CCoommppoonneennttss ooffCCLLRR

    The CLR contains the following components.

    n Security Manager / Code safety verifiern JIT Compilern Memory Managern Garbage Collectorn Exception Manager

    33.. SSeeccuurriittyy MMaannaaggeerr // CCooddee SSaaffeettyy VVeerriiffiieerrn This is the initial and most component of CLR.n Application security is much more important issues today.n 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 thecurrent 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 securitypermissions 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, remoteor network access etc.

  • 8/2/2019 Dotnet Classes

    25/44

    .NET 3.5 and Visual Studio 2008 Hour 6 - Page 25 of 44

    44.. JJIITT CCoommppiilleerrn As you seen in the diagram of RTE previously, the JIT compiler is responsible for

    compiling theMSIL

    code into the

    Native code

    .

    n The native code is directly understandable by the system hardware.

    55.. MMeemmoorryy MMaannaaggeerrn The Memory Manager component of CLR, allocates necessary memory for the

    variables and objects that are to be used by the application.

    66.. GGaarrbbaaggee CCoolllleeccttoorrn This component of CLR de-allocates or cleans-up the un-necessary memory of the

    application, after usage automatically.

    n Instead, in older languages such as C/C++ this kind of component is not available sothat the programmer should free-up the memory explicitly using some code.

    77.. EExxcceeppttiioonn MMaannaaggeerrn An exception means Run time error.n This component redirect the processor to execute the catch block or finally block,

    whenever an exception is occurred at run time.

    n We can learn how to write these catch and finally blocks in C#.NET and VB.NETlanguages later.

    NNaammiinngg CCoonnvveennttiioonn

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

    22..VVaarriiaabblleess aanndd oobbjjeeccttss:: This is programmers 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.

  • 8/2/2019 Dotnet Classes

    26/44

    .NET 3.5 and Visual Studio 2008 Hour 1 - Page 26 of 44

    TThhee ..NNEETT FFrraammeewwoorrkkCCllaassss LLiibbrraarryy ((FFCCLL)) AArrcchhiitteeccttuurree

    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.

    GGeettttiinngg SSttaarrtteedd wwiitthh VViissuuaall SSttuuddiioo 22000088

    II)) OOppeenniinngg VViissuuaall SSttuuddiioo 22000088n Click on StartProgramsMicrosoft Visual Studio 2008Microsoft Visual Studio

    2008.

    n The following screen will be opened.

    System

    Windows Web Drawing Data Xml Linq Threading IO

    PrintingForms UI

    HtmlControls WebControls

    OleDb SqlClient OracleClient

  • 8/2/2019 Dotnet Classes

    27/44

    .NET 3.5 and Visual Studio 2008 Hour 1 - Page 27 of 44

    n Initially, the Visual Studio 2008 will be opened along with Start Page.n The start page is nothing but the welcome page, which contains

    Logo: A logo ofMicrosoft 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 clickon 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 andVisual 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).

  • 8/2/2019 Dotnet Classes

    28/44

    .NET 3.5 and Visual Studio 2008 Hour 1 - Page 28 of 44

    IIII)) TThhee VViissuuaall SSttuuddiioo 22000088 BBaassiiccssTo 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 differenttypes such as Console application, Windows application, Windows Service, Web

    site etc.

    n Solution: Collection of one or more projects. Initially, in a solution, one projectwill be placed. Later, you can add other projects to it.

    n Build: Compilation of entire .NET Project.n Class:A collection of data members and methods (member functions).

    Ex:

    n Namespace: Its nothing but a collection of classes. It may also contain subnamespaces. 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 userdefined namespace.

    Ex:

    namespace MyApplication

    {

    class class1

    {

    }

    class class2

    {

    }

    }

    class class1

    {

    int mydatamember;

    private void mymethod()

    {

    }

    }

  • 8/2/2019 Dotnet Classes

    29/44

    .NET 3.5 and Visual Studio 2008 Hour 1 - Page 29 of 44

    IIIIII))CCrreeaattiinngg aa nneeww pprroojjeeccttTo create a new project in Visual Studio, follow the steps given below.

    n Open Microsoft Visual Studio 2008.n Click on FileNewProject.

    n In the New Project dialog box, the left side panel displays the list of .NETlanguages like

    Visual C#

  • 8/2/2019 Dotnet Classes

    30/44

    .NET 3.5 and Visual Studio 2008 Hour 1 - Page 30 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

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

  • 8/2/2019 Dotnet Classes

    31/44

    .NET 3.5 and Visual Studio 2008 Hour 1 - Page 31 of 44

    n Provide the following details:n Name: Specifies the name of the project.

    Ex: WindowsFormsApplication1.n Location: Specifies the path, in which the project is to be stored.n 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).

    n 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.

    IIVV))PPrroojjeecctt DDiirreeccttoorryy SSttrruuccttuurreeWhen 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.

  • 8/2/2019 Dotnet Classes

    32/44

    .NET 3.5 and Visual Studio 2008 Hour 1 - Page 32 of 44

    n Each project will be created as a folder, and placed in the solution folder.n All the files related to the project, will be placed in the project folder.n 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.

    n In the same way, the information about the project members will be saved in theProject 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 previousexample.

    Solution Folder:

    Project Folder Solution File

  • 8/2/2019 Dotnet Classes

    33/44

    .NET 3.5 and Visual Studio 2008 Hour 1 - Page 33 of 44

  • 8/2/2019 Dotnet Classes

    34/44

    .NET 3.5 and Visual Studio 2008 Hour 1 - Page 34 of 44

    Project Folder:

    bin: Thisfolder contains the EXE file after compiling the project. obj: Thisfolder 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): Thisfilecontains the information aboutall 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 ofForm1. Form1.Designer.cs: Thisfilecontains the code related to the design of Form1. Program.cs: This file contains the code ofProgram class with Main() method.

  • 8/2/2019 Dotnet Classes

    35/44

    .NET 3.5 and Visual Studio 2008 Hour 1 - Page 35 of 44

    CCoommppoonneennttss ooffVViissuuaall SSttuuddiioo IIDDEE

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

    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 usedoptions 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.

    Menu Bar Tool Bars Form Designer Solution Explorer

    Toolbox Properties window

    Tabs

  • 8/2/2019 Dotnet Classes

    36/44

    .NET 3.5 and Visual Studio 2008 Hour 1 - Page 36 of 44

    5) Code Window: This is where you write actual programming of your application. Youcan 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 arealso 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.

    VV))CCrreeaattiinngg CCoonnssoollee AApppplliiccaattiioonnssThe console applications are the project types, recommended for the .NET programming

    beginners, where you can learn the language features better.

  • 8/2/2019 Dotnet Classes

    37/44

    .NET 3.5 and Visual Studio 2008 Hour 1 - Page 37 of 44

    n In Microsoft Visual Studio 2008, click on FileNewProject.n Select the language as Visual C# and select the project template as Console

    Application.

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

  • 8/2/2019 Dotnet Classes

    38/44

    .NET 3.5 and Visual Studio 2008 Hour 1 - Page 38 of 44

    C#.NET

    OOvveerrvviieeww

    n Its a programming language, offered by .NET Framework.n It is recommended for both .NET programming beginners and .NET professionals.n This is the mostly used languages used by most of the IT companies today.n

    It derives some programming features fromC

    andC++

    also.

    n It is the object oriented programming language.n The programmer, having knowledge in C and C++ can easily understand the

    programming in C#.

  • 8/2/2019 Dotnet Classes

    39/44

    .NET 3.5 and Visual Studio 2008 Hour 1 - Page 39 of 44

    FFiillee EExxtteennssiioonnss iinn CC##n Project File Extension: .csproj (means C Sharp Project)n Code File Extension: .cs (means C Sharp)

    SSaammppllee AApppplliiccaattiioonn DDeevveellooppmmeenntt iinn CC##

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

  • 8/2/2019 Dotnet Classes

    40/44

    .NET 3.5 and Visual Studio 2008 Hour 1 - Page 40 of 44

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

    Application 1: A simple C# program

  • 8/2/2019 Dotnet Classes

    41/44

    .NET 3.5 and Visual Studio 2008 Hour 1 - Page 41 of 44

    AA cclloosseerr llooookkaatt tthhee ssyynnttaaxx

    11.. IImmppoorrttiinngg sseeccttiioonn:: 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 specifythe parent and child namespaces separated with . (dot).

    Ex:

    Importing section Namespace Declaration Class Declaration

    Main() method

  • 8/2/2019 Dotnet Classes

    42/44

    .NET 3.5 and Visual Studio 2008 Hour 1 - Page 42 of 44

    using System;

    using System.IO;

    using System.Data;etc.

    22.. NNaammeessppaaccee ddeeccllaarraattiioonn:: 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.

    22.. CCllaassss ddeeccllaarraattiioonn:: 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 cant

    change it.

    A startup class nothing but a class, which contains Main() method.Syn:

    class classname

    {

    }

    33.. MMaaiinn(()) mmeetthhoodd:: 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.

  • 8/2/2019 Dotnet Classes

    43/44

    .NET 3.5 and Visual Studio 2008 Hour 1 - Page 43 of 44

  • 8/2/2019 Dotnet Classes

    44/44

    Syn:

    Specifies that Main() is a static method; to enable

    JIT, to directly call Main() method directly,without creating an instance ofProgram class.

    Means no return value

    Receives arguments sent

    to the Main() method in a

    string array format.