Vous êtes sur la page 1sur 23

Lesson: 1. 1. What is .NET Framework? Ans: The .

NET Framework is the foundation on which we can design, develop, and deploy applications. t is the core of the .NET infrastructure. t e!ists as a layer "etween the .NET applications and the underlying operating system. The .NET Framework summari#es much of the "asic functionality, such as de"ugging and security services, which was earlier "uilt into various programming languages. 2. What does .NET Framework consists of? Ans: The .NET Framework consists of $e" forms, $indows forms, and console applications that relate to the presentation layer of an application. $e" forms are used in $e"%"ased applications, whereas $indows Forms are used in $indows%"ased applications for providing an interactive user interface. n addition, we can create character%"ased console applications that can "e e!ecuted from the command line. &esides these three components, the .NET Framework consists of two other components, that is the .NET Framework &ase 'lasses and the 'ommon Language (untime )'L(*. 3. Write short notes on: +ns: .Net Framework comprised of following things: % Programming Methodo ogies: The ,isual -tudio .NET programming methodology allows for mi!ed% language programming. This is esta"lished through a 'ommon Type -ystem )'T-* that is defined for all the languages that .NET Framework supports. +ll these languages compile into an intermediate language "efore they compile in native code. Therefore, the .NET developer has the independence to code one module of an application in one language and the other module of the same application in another language. P atform Techno ogies: ! The .NET Framework includes platform technologies like +./.NET, +-0.NET, and ,&.NET. +./.NET allows .NET applications to communicate with a data"ase for retrieving, accessing, and updating data. +-0.NET is a framework for "uilding enterprise%class $e" applications. ,&.NET is an o"1ect%oriented language that provides features such as a"straction, encapsulation, and polymorphism. &y using these technologies, we can easily develop ro"ust $e" applications, $indows applications, and 23L $e" services. "ode E#ec$tion: ! The code e!ecution process involves the conversion of ntermediate Language into native or '04%specific code. The 'L( is completely architecture%neutral. +ll the .NET languages get compiled into the L. This intermediate language gets compiled "y 5ust%in%Time )5 T* compiler into the native machine code. +fter translating the L into native code, the converted code is sent to the .NET runtime manager. The .NET runtime manager e!ecutes the code. $hile e!ecuting the code, a security check is performed to ensure that the code has the appropriate permissions for accessing the availa"le resources. %. Which are the P atform techno ogies s$&&orted '( .NET framework? +ns: -ome of the platform technologies supported "y .NET Framework are: 6+./.NET 6+-0.NET 6,&.NET. 6+./ .Net is the technology that is used to access the data"ases. .Net has improved that kind of programming significantly from an ease%of%use standpoint, through some features. The net effect of +./ .Net for the developer has greatly simplified and enhanced capa"ility of programming with data"ases. 6 nternet was the certainly one of the keystone of the development of .Net, we can understand from the name. The particular part of the technology, which deals with nternet, is called +-0 .Net. The idea for developing s7w for the nternet can "e tricky. t "ecomes trickier, if we are trying to have reasona"le amount of programming logic sitting "ehind a we" page. 6+nother place where .Net has innovated is in 84ser nterface .esigning9. t was started in the world of ,isual &asic. 6 n '::, we struggle with hacking code to position our "uttons and our te!t "o!es, where as the ,isual "asic user were 1ust dragging them on the screen and putting them where they wanted them. 6That9s the "eauty of the tools that 3icrosoft has "uilt, that work with those languages. 6The $indow programs run under .Net, which are designed visually, are called ;$in%Forms<. 6.NET supports a concept called data "inding that lets that happen completely automatically. The data source for this grid is this particular dataset, and that is the end of it. f we change the dataset, the grid updates automatically. f we change the grid programmatically, it updates into the dataset, and then we can decide whether to commit those changes to the data"ase. t is a very nice and very powerful concept. ). What is 'ackward com&ati'i it(?

+ns: &ackward compati"ility refers to the a"ility of a technology to work with its previous versions or with other earlier technologies. For e!ample, the +ctive .irectory structure of $indows =>>> is "ackward compati"le with $indows NT ?.@1 and A.>. -imilarly, the .NET Framework supports "ackward compati"ility. t is capa"le of running applications developed in ,isual -tudio on ,isual -tudio .Net. For e!ample, we can compile and run applications created in ,isual &asic B.> in ,isual -tudio =>>@. *. +ist o$t the ad,antages of .NET framework. +ns: The .NET Framework provides num"er of advantages to the developers, which are state "elow C i. "onsistent Programming Mode : % Every programming language has different approaches for doing a task. 66For e!ample, accessing data with a ,& application and a ,':: application is totally different. + developer has to know "oth different techniDues to do the task. 6The .NET 'lass Li"rary provides the functionality to all .NET languages resulting in a consistent o"1ect model regardless of the programming language used "y the developer. ii. +ang$age -nde&endence: % Language ndependence means the developer has the freedom to code one module of an application in one language and other module of same application in other language. 6This language interopera"ility can help in code reuse and improve the efficiency of the development process. iii. No ,ersioning Pro' em: % t makes deployment of applications very easy. 6The .NET ensures that all the components the application depends on are availa"le on the computer "efore the application "egins to run. iv. -m&ro,ed .ec$rit(: % The .NET Framework provides several mechanisms for protecting resources and code from unauthori#ed users: 66 a./ +-0.NET $e" +pplication -ecurity provides a way to control access to a we" site "y comparing authenticated permissions with File -ystem permissions for proper authori#ation. './ 'ode access security uses permissions to control the code accessing protected resources and operations. c./ (ole%"ased security provides information needed to make decisions a"out user9s permissions. v. .$&&ort for We' .er,ices: % $ith the advent of .NET technology, we" services provide many "uilt in &ase 'lass li"rary facilities, which open up a whole new world of information for users. 6$e" services can provide everything from "asic te!t news information to vital data"ase or application information. vi. 0(namic We': % .ynamic we" content is easier to create with .NET. +-0.NET and ,isual -tudio.NET allow developers to create dynamic we" much easier than - and +-0 technologies. vii. 1is$a .t$dio .NET: %,isual -tudio .NET is the 3icrosoft application and interface for programming in .NET ,isual -tudio.6This development environment has e!tensive set of ready to use controls, good de"ugging facilities, easy and simple programming features and vast set of .NET &ase 'lasses. 2. 0oes .NET & atform s$&&ort 'ackward com&ati'i it(? E#& ain. +ns: The .NET platform supports "ackward compati"ility. t is possi"le for an application compiled in one version of the .NET Framework to run on a different version of the .NET Framework. For e!ample, we can run applications developed in ,isual -tudio =>>=7=>>? on ,isual -tudio =>>@. The .NET platform supports "ackward compati"ility in the following ways: The .NET Framework =.> &'L supports "ackward compati"ility with the earlier versions. .NET supports ':: "ecause of "ackward compati"ility. To run a ':: code on .Net Framework, we need to include the following line at the "eginning of the code: 3$sing 4mscor i'.d 5 ,& applications can work on ,&.NET and +-0 applications can run on +-0.NET "ecause of "ackward compati"ility. $e can easily reference '/3 components in.NET applications. +esson 2: 1. With a neat diagram6 e#& ain the .NET Framework architect$re. +ns: The .NET Framework is the foundation on which we design, develop, and deploy applications.

The .NET Framework consists of +-0.NET $e" Forms, $indows Forms, and 'onsole applications that affect to the presentation layer of an application. $e" Forms are used in $e"% "ased applications, whereas $indows Forms are used in $indows%"ased applications for providing an interactive user interface. n addition, we can create character%"ased console applications that can "e e!ecuted from the command line. &esides these three components, the .NET Framework consists of two other components, the .NET Framework &ase 'lasses and the 'ommon Language (untime.

2. +ist o$t the o'7ecti,es of .NET framework? +ns: The o"1ectives of .NET framework are as following: i* To provide an o"1ect%oriented programming environment whether o"1ect codes is stored and e!ecuted locally, or e!ecuted remotely. ii* To provide a code%e!ecution environment that minimi#es software deployment and versioning conflicts. iii* To provide a code%e!ecution environment that guarantees safe e!ecution of code, including code created "y an unknown or semi%trusted third party. iv* To provide a code%e!ecution environment that eliminates the performance pro"lems of scripted or interpreted environments. 3. 8ow the Windows Programming is different from .NET Programming? +ns: $indows 0rogramming is different from .NET 0rogramming in following ways C Windows Programming: ! n $indows 0rogramming, the application programs call windows +0 function directly. The applications run in the windows environment i.e. operating system itself. These types of applications are called unmanaged or unsafe applications. .NET Programming: % n .NET 0rogramming the application programs call .Net &ase 'lass li"rary functions which will communicate with operating system. The applications run in .Net (untime environment. These types of applications are called as managed or safe applications. The .Net &ase classes are fully o"1ect%oriented. t provides all functionalities of traditional windows +0 along with functionalities in new areas like accessing data"ase, nternet connections and we" services. *. What are the f$nctiona ities of "+9? :i,e the ste&s in,o ,ed in the managed e#ec$tion &rocess. +ns: The 'L( has the following functionalities: The 'L( uses metadata to locate and load classes, lay out instances in memory, resolve method invocations, generate native code, enforce security, and set runtime conte!t "oundaries. The 'L( automatically handles o"1ect layout and manages references to o"1ects, releasing them when they are no longer "eing used. +utomatic memory management eliminates memory leaks as well as some other common programming errors. The 'L( makes it easy to design components and applications whose o"1ects interact across languages. /"1ects written in different languages can communicate with each other, and their "ehaviors can "e tightly integrated. The managed e#ec$tion &rocess inc $des the fo owing ste&s: 1. 'hoosing an appropriate language compiler. =. 'ompiling your code to 3- L or simply L: 'ompiling translates your source code into L and generates the reDuired metadata. ?. 'ompiling L to native code: +t e!ecution time, a 5 T compiler translates the L into the native machine code. .uring this compilation, the code must pass a verification process that e!amines the L and metadata to find out whether the code can "e determined to "e type safe.

A. E!ecuting code: The 'L( provides the environment that ena"les e!ecution as well as a variety of services that can "e used during e!ecution. 2. 8ow the .NET e#ec$tion en,ironment with a&& ication domain differs from traditiona wa( of e#ec$tion? Ans: .NET e#ec$tion en,ironment differs from traditiona wa( of e#ec$tion in fo owing manners: a* f we are writing application in 'E compiler or writing in ,isi"le &asic, we need a ,isual &asic compiler, even for '::, we need a ':: compiler. &ut in .Net e!ecution environment, the approach taken here is that all of those compilers compile into this same intermediate language. "* The intermediate language is then compilers compile into this same intermediate language. c* -o, it really doesn9t matter what language we write our code in, it all compiles into same ntermediate language. d* 5ust% n%Time compiler only needs to understands one language, not all of them,. t only needs to understand the ntermediate Language. e* t compiles it into native code and naturally, that does not take place until run time. f* This process is completely automatic and independent of how the program is coded.

%. 0efine the fo owings:! "ommon T(&e .(stem ;"T./ ! This is a standardi#ed agreed set of "asic data types. This system provides a way for language interopera"ility. Language nteropera"ility means that an o"1ect implemented in one language can call a o"1ect implemented in another language. n more general way you can say that an application can "e developed in two or more languages supported "y .Net framework. To make use of language interopera"ility feature, the developers have to follow 'T-. "ommon +ang$age .&ecification ;"+./ ! The set of rules of "asic language features has "een defined to enhance and ensure language interopera"ility is called the 'ommon Language -pecification )'L-*. The 'L- rules define a su"set of the 'T-. "+9 ! 'ommon Language (untime )'L(* is also known as .NET (untime. The code management is a fundamental principle of the runtime. The responsi"ility of runtime is to load the code, run the code and provide all kinds of services. The services provided "y .NET (untime are as memory management, thread management, remoting, strict type safety, ensure code security and ro"ustness. Managed "ode ! The code that is developed with a language compiler that targets the 'L( is called managed code. 3anaged code is one, which is designed to run on .Net environment. The code which runs in windows environment is unmanaged code. -ntermediate +ang$age ;-+/ % This is also called as 3icrosoft ntermediate Language )3- L*. The intermediate language is analogous to the "yte code of 5ava. The significant difference is that the "yte code in interpreted while the L is compiled "y 5 T compilation to native machine code. The L code is not the machine code. The .Net (untime calls the 5ust%in%Time )5 T* compiler to get native machine code from L code. This feature makes the .NET platform independent. .NET <ase " asses ! .NET &ase 'lasses is a li"rary comprising of e!tensive set of functions for all services supported "y the framework. This vast collection has well written code for almost all tasks on all services of .Net framework. The services can "e windows creation7displaying or form handling, nternet or we" services, data"ase accessing or file handling. Assem' ies ! +n +ssem"ly is the unit in which compiled managed code is stored. +n +ssem"ly contains L and metadata. 3etadata gives details of the assem"ly, properties and methods stored in it, security information. 9ef ection ! The process of o"taining information a"out assem"lies and the types defined within them as metadata at runtime. =$st!in!Time ;=-T/ "om&i ation ! The compilation converts L into its native machine code. The name 5ust%in%Time is "ecause it compiles portion of code as and when reDuired at run time. Manifest ! The area of assem"ly where metadata is stored is called as manifest.

A&& ication 0omain ! + "oundary that the common language runtime esta"lishes around o"1ects created within the same application is "y means of +pplication .omain. +pplication domain allows different code to run in the same process space. :ar'age "o ection ! The Far"age 'ollector frees the application from the responsi"ility of freeing memory when no longer reDuired. 'L( calls Far"age collector to handle memory efficiently. ). What are assem' ies? What are static and d(namic assem' ies? +ns: +n +ssem"ly is the unit in which compiled managed code is stored. +n +ssem"ly contains L and metadata. 3etadata gives details of the assem"ly, properties and methods stored in it, security information etc. +ssem"lies can "e static or dynamic. .tatic assem' ies can include .NET types )interfaces and classes*, as well as reDuired resources for the assem"ly )"itmaps, 50EF files, resource files, and so on*. -tatic assem"lies are stored on disk in 0E files. 0(namic assem' ies are one, which run directly from memory and are not saved to disk "efore e!ecution. They can "e saved disk after they have e!ecuted. >. Write a note on Metadata. +ns: Metadata: % n earlier days, it was not possi"le that s7w component7module ).e!e or .dll* written in one language could get used in another module, which is written in another language. The solution came in the form of '/3 components are: 6The .Net Framework makes language interoperation even easier "y allowing compilers to put additional information into all compiled modules and assem"lies. This information is called 3etadata. 63etadata is "inary information descri"ing the program. $hen we compile our code into 0E file, metadata is inserted into one portion of the 0E file, while the code is converted to L and inserted into another portion of the 0E file. 6Every type, mem"er, which are defined or referenced in a module, is descri"ed within metadata. $hen code is e!ecutedG the runtime loads metadata into memory and refers it to get information a"out the codes class, mem"ers, and inheritance and so on. 63etadata allows .NET languages to descri"e themselves in a language%neutral manner. 6 t gives reDuired information to 'L( to perform much of its functionalities. 6The present of metadata makes the assem"ly -elf%descri"ing file. 6The 'L( modules or components or other assem"lies, which want to communicate with each other users, these information stored in metadata to perform their tasks. 6 t stores information like: % a/ .escription of the assem"ly9s operation. '/ +ssem"ly dentity. c/ E!ported types. d/ /ther dependent assem"lies. e/ -ecurity permissions. f/ .escription of types. g/ 3em"ers like methods, fields, properties, events, nested types, etc. h/ +ttri"utes. ?. What is the f$nction of "T.? E#& ain the c assification of t(&es in "T. with a diagram. Ans: The 'ommon Type -ystem )'T-* defines how types are declared, used and managed in the runtime. t is an important for Language nteropera"ility. t performs the following functions: 1* -tart a common framework that ena"les cross%language integration, type safety, and high performance code e!ecution. =* 0rovides an o"1ect%oriented model. ?* .efines rules that languages must follow, so that different languages can interact with each other. " assifications of t(&es in "T. are as fo ows: 1. 1a $e t(&es 2. 9eference t(&es

a* ,alue types directly stores data in the varia"le. ,alue types can "e "uilt%in type, user%defined types, or enumerations.

"* (eference types store a reference to the data9s memory address. (eference types can "e self descri"ing types, pointer types, or interface types. -elf%descri"ing types are further split into arrays and class types. c* The class types are user%defined classes, "o!ed value types, and delegates. d* +ll types derive from the -ystem. /"1ect "ase types .

1@. A-t is to d that if we earn an( one .NET ang$age6 then working with other .NET ang$ages wi 'e eas(B. 8ow? E#& ain with the a&&ro&riate e#am& e. +ns: t can "e told that if you have learned any one .NET language, then working with other .NET languages will "e easy. This is "ecause all the .NET languages rely on the same managed classes of &'L for the same services. The same classes, methods, parameters, and types are used for all the system services regardless of any .NET language. Let us look at the following code that writes to and then reads from a file: // Program in C# using -ystemG using -ystem. /G static pu"lic void 3ain)* H -tream$riter sw1Inew -tream$riter)Jtemp.t!tJ, true*G string tempstringIJKi, this is FopalJG sw1.$riteLine)tempstring*G sw1.'lose)*G -tream(eader sr1Inew -tream(eader)Jtemp.t!tJ*G string filestringIsr1.(eadToEnd)*G sr1.'lose)*G 'onsole.$riteLine)filestring*G L // Program in VB.NET shared pu"lic su" 3ain)* dim sw1 as -tream$riterInew -tream$riter)Jtemp.t!tJ, true* dim tempstring as stringI JKi, this is FopalJ sw1.$riteLine)tempstring* sw.'lose)* dim sr1 as -tream(eaderInew -tream(eader)Jtemp.t!tJ* dim filestring as stringIsr1.(eadToEnd)* sr1.'lose)* 'onsole.$riteLine)filestring* end su" f we see, "oth versions of the a"ove program are nearly identical. The synta! and use of -tream(eader, -tream$riter, and the 'onsole class are identical, same methods, and identical parameters.

Lesson: 3.
1. +ist o$t the im&ortant feat$res of "3? Ans: -m&ortant feat$res of "3 are: 'E is a stylish, simple, type%safe, o"1ect%oriented language. 'E has the a"ility to "uild ro"ust system%level components due to following features: 66 Full '/370latform support for e!isting code integration. 66(o"ustness through gar"age collection and type safety. 66-ecurity provided through good design. 66Full support of e!tensi"le metadata concepts. 'E supports Language nteropera"ility and 0latform ndependence due to following features: 66Full interopera"ility with '/3 and .NET Framework services, through tight .NET Li"rary &ase classes. 66 23L support for we"%"ased component interaction. 66,ersiona"ility.

2. Write a &rogram in "3 to dis& a( AWe come to the wor d of " .har&B. E#& ain the &rogram. +ns: 77 + ;$elcome to the world of ' -harp< program in 'E class $elcome H pu"lic static void 3ain )stringMN ar* H 'onsole.$riteLine );$elcome to the world of ' -harp<*G L L 0escri&tion of the a'o,e written &rogram C "omments: % 'omments are used for proper documentation of the code. The compiler does not consider the comments as the part of code. 'ompiler ignores the comments during the time of compilation. 'omments make the program more understanda"le. 'E accepts the ':: style of comments. The Main Method: % Program execution begins with the Main method. The 'E program must contain a 3ain method, in which control starts and ends. $e can create o"1ects and e!ecute other methods within this 3ain method. -n&$t and D$t&$t: % n the a"ove $elcome program there is only one output statement, no input statements. The statement: -ystem.'onsole.$riteLine);$elcome to the world of ' -harp<*G uses the $riteLine method, of the 'onsole class which resides in the .NET run%time li"rary. This method displays its string parameter on the standard output. "om&i ation and E#ec$tion: % 6&y using any te!t editor create a source file and save it as $elcome.cs. The 'E source code files should have .cs e!tension.6To compile the program use the command given "elow. f there are no compilation errors $elcome.e!e is created. csc $elcome.cs 6 To run the program, enter the command % $elcome t will display ;$elcome to the world of ' -harp< on the console. 3. E#& ain the genera str$ct$re of a "3 &rogram. +ns: 'E program can consist of one or more files. Each file can contain one or more namespaces. + namespace contains group of related types such as classes, structs, interfaces, enumerations, and delegates. Namespaces may "e nested. The following is the skeleton of a 'E program that contains all of these elements. 77 + skeleton of a 'E program using -ystemG 6namespace Namespace1 6H class 'lass1 6HL 6 struct -truct1 6 HL 6interface nterface1 6HL 6 delegate int .elegate1)*G 6enum Enum1 6HL 6 namespace Namespace= 6HL 6class 'lass= 6H pu"lic static void 3ain)stringMN args* 6HLLL %. 8ow do names&aces and t(&es in "3 ha,e $niE$e names? :i,e an e#am& e. Ans: Namespaces and types always have uniDue names. For e!ample, f there are = class with same name "ut are present in different namespaces then "oth the o"1ects will have their uniDue fully Dualified names. namespace +&' H class 'lass1 HL L namespace 2OP H class 'lass1 HL L Kere the +&'.'lass1 and 2OP.'lass1 are two different types, even if the class name is same. n the following code e!ample shows the nested classes and namespaces. namespace +&' H class 'lass1 H class 'lass= HL L namespace 2OP 77 +&'.2OP H class 'lass= HL L L From the a"ove code e!ample: The namespace +&' is a mem"er of the glo"al namespace. ts fully Dualified name is +&'. The namespace 2OP is a mem"er of +&'. ts fully Dualified name is +&'.2OP. The class 'lass1 is a mem"er of the +&'. ts fully Dualified name is +&'.'lass1. The class name 'lass= is used twice in this code. Kowever, the fully Dualified names are uniDue. The first one is declared inside 'lass1G thus its fully Dualified name is: +&'.'lass1.'lass=. The second is declared inside a namespace 2OPG thus, its fully Dualified name is +&'.2OP.'lass=. 4sing the preceding code segment, we can add a new class mem"er 'lass? to the namespace +&'.2OP as follows: namespace +&'.2OP H class 'lass? HL L *. +ist o$t the difference 'etween "3 and "FF. +ns: Following are the differences "etween 'E and ':: 'E is purely o"1ect%oriented language, whereas ':: supports o"1ect%oriented programming. Arra(s: The synta! of declaring 'E arrays is different from that of ':: arrays. The tokens ;MN< appear following the array type in 'E. The 'oo t(&e in "3: There is no conversion "etween the "ool type and int. The long type: n 'E, the long data type is BA "its, while in '::, it is ?= "its. The str$ct t(&e: n 'E, classes and structs are semantically different. + struct is a value type, while a class is a reference type. The switch statement: 4nlike the ':: switch statement, 'E does not support fall through from one case la"el to

another. The de egate t(&e: .elegates are roughly similar to function pointers in '::, "ut they are type%safe and secure. 0reprocessor directives are used for conditional compilation. No header files are used in 'E. 'E operators: 'E supports additional operators such as is and type of. t also introduces different functionality of some logical operators. The 3ain method is declared differently from the main function in '::. The usages of the command%line arguments are also different. Method &arameters: 'E supports ref and out parameters, which are used instead of pointers in passing parameters "y reference. 0ointers are allowed in 'E "ut only in unsafe mode. /verloading operators is performed differently in 'E. .trings: 'E strings are different from ':: strings. The foreach keyword allows you to iterate through arrays and collections. No glo"al methods or varia"les in 'E: 3ethods and varia"les must "e contained within a type declaration. No header files or Einclude directives in 'E: The using directive is used to reference types in other namespaces without fully Dualifying the type names. 0estr$ctors: n 'E, you don9t have control over when a destructor is called "ecause destructors are called automatically "y the gar"age collector. "onstr$ctors: 4nlike '::, if you don9t provide a class constructor in 'E, a default constructor is automatically generated for you. The default constructor initiali#es all the fields to their default values. 'E does not support "it fields. Lesson: % 1. Which are two different categories of t(&e in "3? +ns: There are two different categories of type in 'E are C Gi.H 1a $e t(&e Gii.H 9eference t(&e. 1/ 1a $e t(&es: % They directly contain data.Q The varia"le have their own copy of the data.Q + varia"le of a type always stores a data value of that type.Q +ssignment to a value type varia"le creates a copy of the value "eing assigned.Q -ome e!amples of the ,alue type are C char, int, float. 2/ 9eference t(&es: % The (eference type does not contain data "ut they contain a reference to the varia"les, which are stored in memory. Q 4sing more than one varia"les, we can use reference types to refer to a memory location. Q This means that if the value in the memory location is modified "y one of the varia"les, the other varia"les automatically reflect the changed value. Q n reference type, it is possi"le for a data to reference an o"1ect of other derived type.Q +ssignment to a reference type varia"le, copies the address of o"1ect.Q -ome e!amples of (eference type are C class, string, interface, array, delegate type. 2. What are ,aria' es? 8ow man( categories of ,aria' es are there in "3? 0efine each. Ans: + varia"le is a location in the memory that has a name and contains a value. The ,alue could "e an integer, decimal, character, string. + varia"le is associated with a data type that defines the type of data, which can "e stored in a varia"le. ,aria"les can "e initially assigned or initially not assigned. n 'E varia"les are categori#ed in R categories they are: i/ .tatic ,aria' es: ! + varia"le declared with the static modifier is called a static varia"le. There will "e only one copy of the varia"le, regardless of how many instances of class are created. ii/ -nstance ,aria' es: ! + varia"les declared without the static modifiers are instance varia"les. iii/ Arra( e ements: ! The array is a container that has a list of storage locations for a specified type. The elements for a specified type of an array come into e!istence when an array instance is created, and e!ist until there are no references to that array instance. i,/ 1a $e &arameters: ! 0arameters are arguments passed to the function. + parameter declared without a ref or out modifier is a value parameter. + value parameter e!ists until the function returns. v* 9eference &arameters: ! + parameter declared with a ref modifier is a reference parameter. + reference parameter does not create a new instance, it points to the same storage location of the parameter passed as an argument. ,i/ D$t&$t &arameters: ! + parameter declared with an out modifier is an output parameter. + reference parameter does not create a new instance, it points to the same storage location of the parameter passed as an argument. &ut output parameter must "e definitely assigned "efore the function returns. ,ii/ +oca ,aria' es: ! + local varia"le is declared and e!its within a "lock, for% statement, switch% statement, using statement. + local varia"le is not automatically initiali#ed, thus has no default value. 3. What is the im&ortance of a$tomatic memor( management? E#& ain with e#am& e?

Ans: n earlier days, developers need to manage the allocation and de%allocation of "locks of memory, which is known as 3anual memory management. 3anual memory management can "e "oth time% consuming and difficult. Q &ut in .NET Framework, 'L( provides a run%time environment, which manages the e!ecution of code and provides essential services like +utomatic memory management. Q +utomatic memory management eliminates memory leaks as well as some other common programming errors. Q n 'E, automatic memory management is provided so that developers are freed from this "urdensome task. Q +utomatic memory management increases code Duality and enhances developer productivity without negative impact on either e!pressiveness or performance. %. Write a note on e#&ression and o&erators in "3. +ns: E#&ression: % +n e!pression is a seDuence of operators and operands that specifies computation and assigns the result to a varia"le. E!pressions are constructed from operands and operators. The operators of an e!pression indicate which operations to perform. Examp es !or operators are "# $# %# &# etc.

Examp es !or operands are itera s# 'ariab es# and expressions.


D&erators: % There are three types of operators 4nary, &inary, Ternary. +pplication use operators to process the data entered "y a user. /perators like : and C are used to process varia"les and return a value. +n operator is a set of one or more characters that is used for computations or comparisons. /perator can transform one or more data values, called operands, into a new data value. -ome e!amples of /perators are +rithmetic, +rithmetic +ssignment, 4nary, 'omparison, Logical operators. *. What are em&t( statement and a'e ed statements? Wh( are the( $sed? Ans: Em&t( statement: ! +n empty statement )S* simply transfers control to the end point of the statement. t is used when there are no operations to perform, "ut reDuire a statement. +n empty statement can "e used when writing a while statement with a null "ody and can also "e used to declare a la"el 1ust "efore the closing ;L< of a "lock. +a'e ed statement: ! + la"eled statement is prefi!ed "y a la"el. La"eled statements are permitted in "locks. + la"el is a name given "y the identifier. The scope of a la"el is the "lock in which the la"el is declared. f two la"els have same name we get compile time error. + la"el can "e referenced from goto statements within the scope of the la"el. La"els and other identifiers can have same name. ). What is an iterati,e statement? E#& ain foreach statement with e#am& e? Ans: terative statements repeatedly e!ecute a "lock of statements. Q The num"er of iterations depends on the condition represented "y &oolean e!pression. Q The "lock of code will "e iterated until the condition is true. Foreach statement: C + foreach statement lets us iterate over the elements in arrays and collections.Q The elements of single%dimensional arrays are traversed in increasing order of inde!, starting with inde! > to Length%1.Q The elements of multi%dimensional arrays elements are traversed such that the indices of the rightmost dimension are incremented first, then the ne!t left dimension, and so on to the left.Q Following e!ample uses a foreach statement to iterate over the elements of an array C using -ystemG class ForEachE!ample H static void 3ain )* H intMN arr Inew intMN H1,=,?,ALG foreach )int i in arr* 'onsole.$riteLine );,alue is H>L<, arr*G L L ?. What are checked and $nchecked statements? :i,e E#am& e. Ans: The checked and unchecked statements are used to control the overflow checking for integer type arithmetic operations and conversions . "hecked .tatement: ! The 'hecked statement causes all e!pressions in the checked "lock to "e evaluated in a checked conte!t. Inchecked .tatement: ! The 4nchecked statement causes all e!pressions in the unchecked "lock to "e evaluated in an unchecked conte!t. e.g.: % using -ystemG class E!T'heckT4ncheck Hstatic void 3ain)* H int ! I nt?=.3a!,alueG 'onsole.$riteLine)! : 1*G 77 /verflow checked H 'onsole.$riteLine)! : 1*G 77 E!ception L unchecked H 'onsole.$riteLine)! : 1*G 77 /verflow L J L >. :i,e an e#am& e ock and $sing statements.

Ans: +ock .tatements: ! The lock statement o"tains the mutual e!clusion lock for a given o"1ect, e!ecutes statements, and then releases the lock. The e!ample is shown "elow Ce.g.: % static void 3ain)* H + a I ...G lock)a* H a.0 I a.0 : 1G L L Ising .tatements: ! The using statement o"tains one or more resources, e!ecutes statements, and then releases of the resource. e.g.: % static void 3ain)* H using )(esource r I new (esource)** H r.Func)*G L L 2. Which are different 7$m& statements s$&&orted '( "3? Ans: .ifferent 1ump statements supported "y 'E are: % 1/ <reak .tatements: ! $hen there is a need to e!it a loop "efore the loop condition is re%evaluated after iteration. +s with the while loop, we can use "reak statement to e!it from the loop. e.g.: % using -ystemG class E!T&reak H static void 3ain )stringMN ar* H int iI>G while )true* H if )iIIar.Length* "reakG 'onsole.$riteLine )arMi::N*G L L L 2/ "ontin$e .tatements: ! The continue statement is used to skip all the su"seDuent instructions and take the control "ack to the loop. e.g.: % using -ystemG class E!T'ontinue H static void 3ain )stringMN ar* Hint iI>G while )true* H 'onsole.$riteLine )arMi::N*G if )i U ar.Length* continueG "reakG L L L 3/ 9et$rn .tatement: ! 3ethods can either return a type or not. + method that does not return a type must give its return type as 8void9. + method that does return a type must name the type returned. + method will stop e!ecuting and return a value when it reaches a 8return9 statement at any point in its e!ecution. The type returned is given at the end of such a return statementG its type must correspond with the type specified in the method declaration. For e!ample, the following piece of code illustrates this point. e.g.: % using -ystemG class E!T(eturn H static int add )int a, int "* H return a:"G L static void 3ain )* H 'onsole.$riteLine )add)1,=**G returnG L L %/ Throw .tatement: ! $e can throw an o"1ect if the o"1ect is either directly or indirectly derived from -ystem.E!ception. $e can use throw statement in the catch "lock to throw the present o"1ect and we can also throw a new e!ception of a different type. + throw without any e!pression can only "e used in the catch "lock. -uch a throw reverts the e!ception that is currently "eing handled. */ Tr( .tatement: ! The Try "lock guards statements that may throw an e!ception. The "lock governs statements that are enclosed within it and defines the scope of the e!ception handlers associated with it. f an e!ception occurs within the try "lock, an appropriate e!ception handler that is associated with the try "lock handles the e!ception. e.g.: % using -ystemG class E!TThrowTTry H static int F )int a, int "* H if )"II>* throw new e!ception );.ivided "y Pero<*G return a7"G L static void 3ain )* H try H 'onsole.$riteLine )F)@,>**G Lcatch )E!ception e* H 'onsole.$riteLine );Error<*G L L L 1@. 8ow are str$ct$res different from c asses in "3? Ans: Following are the differences "etween -tructures and 'lasses in 'E: %Q -tructures are value types and they get stored in a stack.Q + varia"le of a structure type directly contains the data of the structure, whereas a varia"le of a class type contains a reference to the o"1ect. $e can inherit classes "ut cannot inherit structures. -tructures do not support inheritance.Q -tructures cannot have default constructor. 11. What are interfaces? :i,e an e#am& e. Ans: -nterfaces: % nterface is a syntactical contract that all derived classes should follow. nterface keyword declares a reference type that has a"stract mem"ers. nterface can contain methods, properties, inde!ers and events as mem"ers. They can contain constants, fields, constructors and destructors or any type of static mem"er. +ll the mem"ers of an interface are pu"lic "y definition. e.g.: % interface E!ample H-tring thisMint inde!N H getG setG L event EventKandler EG void Func )int value*G

1)

string 0 Event+rgs*G

HgetG setG L

pu"lic delegate void EventKandler )o"1ect sender,

12. What is de egate? What is the $se of it? :i,e e#am& e? Ans: + .elegate is a reference type varia"le, which holds the reference to a method. Q This reference can "e changed at runtime, as desired.Q .elegates in 'E allow us to dynamically change the reference to the methods in a class.Q .elegates are primarily used in 'E programming for implementing events and the call%"ack methods.Q There are three steps in defining and using delegates: declaration, instantiation and invocation. e.g.: % First declare a delegate "y following synta! C delegate void -imple.elegate)*G using -ystemG class Test H static void F)* H 'onsole.$riteLine);Test.F<*G L static void 3ain )* H -imple.elegate dInew -imple.elegate)F*G d)*G L L 13. Write a &rogram to demonstrate the $sage of en$ms in "3? Ans: using -ystemG Namespace EnumOear H class .isplayOear enum yearH5an,Fe",3arch,+pril,3ay,5une,5uly,+ug,-ept,/ct,Nov,.ecLG ar* H int FirstT3onthI)int*year.5anG int LastT3onthI)int*year..ecG IH>L<, FirstT3onth*G 'onsole.$riteLine);.ec IH>L<,LastT3onth*G L L L H static void 3ain)stringMN 'onsole.$riteLine);5an

1%. Write a note on names&aces in "3. Ans: Names&aces: ! Namespace provides a way to group classes, "y providing an e!tra level of naming "eyond the class name. Q 'E programs are organi#ed using namespaces.Q Namespaces are used "oth as an ;internal< organi#ation system for a program, and as an ;e!ternal< organi#ation system.Q 'lass actually contain data and namespaces are used to logically arrange classes.Q Namespaces can also contain many other Namespaces and classes.Q 'E programs are organi#ed using namespaces. Q Namespaces are implicitly pu"lic and the declaration of a namespace does not include any access modifiers. Q Namespaces can "e nested. 3any namespaces in the "ase class li"rary are nested.Q + namespace declaration consist of the keyword namespace, followed "y a namespace name and "ody: namespace NamespaceName H V.77 namespace "ody L 1*. What is the $se of attri'$te in "3 &rogram? Ans: +ttri"utes are used for adding metadata, such as compiler instructions and other information such as comments, description, methods, and classes to a program. Q 0rograms specify this additional declarative information "y defining and using +ttri"utes.Q +ttri"utes are applied to different elements of the code.Q These element includes assem"lies, modules, structs, enums, constructors, properties, fields and delegates.Q nformation a"out attri"ute is stored with the metadata of the elements they are associated with.

Lesson: *.
1. Write a note on c asses in "3? Ans: 'lass is the collection of 3em"er data and 3em"er functions.Q 'lass declarations are reference type.Q + class can inherit from another class, and can implement interfaces.Q 'lass mem"ers can include constants, fields, methods, properties, events, inde!ers, operators, instance constructors, destructors, static constructors, and nested type declarations.Q Each mem"er has an associated accessi"ility, which controls the portion of program code that is a"le to access the mem"er. There are five forms of accessi"ility. These are as follows: pu"lic, private, protected, protected internal, internal.

2. What are constant mem'ers? :i,e an e#am& e. Ans: + constant mem"er is a class mem"er that represents a constant value. 'onstant mem"ers are initiali#ed at the time of their declaration.Q 'onstants are considered static mem"ers.Q 'onstant

11

mem"er declaration does not reDuire the static modifier. e.g.: % class 'onstant int +I1G pu"lic const int &I+:1G L The a"ove e!ample shows a class named 'onstants that has two pu"lic constants.

pu"lic const

3. :i,e an e#am& e of fie d mem'er. Ans: + field is a mem"er that represents a varia"le associated with an o"1ect or class.Q The fields are initiali#ed at some point "efore they are used, "ut after this initiali#ation they can "e changed. e.g.: ! class 'olor H internal ushort red0artG internal ushort "lue0artG internal ushort green0artG pu"lic 'olor)ushort red, ushort "lue, ushort green* H red0art I redG "lue0art I "lueG green0art I greenG L pu"lic static 'olor (ed I new 'olor)>!FF, >, >*G pu"lic static 'olor &lue I new 'olor)>, >!FF, >*G pu"lic static 'olor Freen I new 'olor)>, >, >!FF*G pu"lic static 'olor $hite I new 'olor)>!FF, >!FF, >!FF*G L

*n the abo'e examp e# the +o or c ass has the !ie ds, redPart# b uePart# greenPart# -ed# . ue# /reen# and 0hite.
%. With a&&ro&riate e#am& es e#& ain &arameter &assing in "3. Ans: n 'E, parameter can "e passed either '( ,a $e or '( reference. 0assing parameters "y reference allows function mem"ers )methods, properties, inde!ers, operators and constructors* to change the value of the parameters and have that change persist. To pass a parameter "y reference, use the ref or out keyword. e.g.: n the following e!ample, it is not the value of my nt that is passedG rather, a reference to my nt is passed. The parameter ! is not an intG it is a reference to an int. therefore, when ! is sDuared inside the method, what actually gets sDuared is what ! refers to: my nt. 4sing -ystemG class 0arameter0assing,al&y(ef H static void -Duare t)ref int !* H ! 6I!G 'onsole.$riteLine);The value inside the method: H>L<,!*G L pu"lic static void 3ain)* H int 3y ntI@G 'onsole.$riteLine);The value "efore calling the method: H>L< ,my nt*G -Duare t)ref my nt*G 'onsole.$riteline);The value after calling the method: H>L<, my nt*G L L *. What is the $se of &ro&ert( mem'er in a c ass? Ans: 0roperty is a mem"er that provides access to a characteristic of an o"1ect or a class. Q 0roperties have accessors that is used to specify the "lock of statement to "e e!ecuted when their values are read or written. Q 0roperties that can "oth read and written, such as caption, include "oth get and set accessors.Q The declaration of properties is relatively straight forward , "ut the real value of properties is seen when they are used. ). What are e,ents? :i,e an e#am& e to demonstrate its $sage. Ans: +n event is an action or occurrence, such as clicks, key presses, mouse movements or system generated notifications. Q +n event is a mem"er that ena"les an o"1ect or class to provide notifications.Q + class defines an event "y providing an event declaration and an optional set of event accessors.Q Events are an affective mean of inter%process communication.Q Events are message sent "y the o"1ect to indicate the occurrence of the event.Q +pplications can respond to events when they occur. e.g.: % using -ystemG pu"lic class Form1 H pu"lic Form1)* H &utton1.'lick :I new EventKandler)&utton1T'lick*G L &utton &utton1Inew &utton)*G void &utton1T'lick )o"1ect sender, Event+rgs e* H 'onsole.$riteLine);&utton1 was 'licked<*G L pu"lic void disconnect)* H &utton1.'lick %I new EventKandler)&utton1T'lick*G L L 2. With an e#am& e e#& ain inde#ers. Ans: +n inde!er ena"les an o"1ect to "e inde!ed in the same way as an array.Q nde!ers ena"le array% like access.Q nde!ers declarations are similar to property declarations, with the main differences "eing that inde!ers are nameless and that inde!ers include inde!ing parameters. e.g.: ! using -ystemG pu"lic class -tack H private Node FetNode)int inde!* H Node temp I firstG while )inde! W >*

12

H temp I temp.Ne!tG inde! X XG L return tempG L pu"lic o"1ect thisMint inde!N H get H if )Y,alid nde!)inde!** throw new E!ception); nde! out of range.<*G else return FetNode)inde!*.,alueG L set H if )Y,alid nde!)inde!** throw new E!ception); nde! out of range.<*G else FetNode)inde!*.,alue I valueGL L L class Test H static void 3ain)* H -tack s I new -tack)*G s.0ush)1*G s.0ush)=*G s.0ush)?*G sM>N I ??G sM1N I ==G sM=N I 11G L L

8. Explain each with an example Instance constructors, Destructor, Static constructor. Ans:a. Instance constructors: - 1n *nstance constructor is ca ed whene'er an instance o! a c ass is created.2 3hese constructors are used to initia i4e data members o! the c ass. e.g.: $ using 56stem7 namespace ca c 8 c ass +a cu ator 8 static int num1#num2#tota 7 +a cu ator9: 8 num1;1)7 num2;2)7 < pub ic 'oid 1dd=umber9: 8 tota ;num1"num27 < pub ic 'oid >isp a6=umber9: 8 +onso e.0rite?ine9@3he tota is 8)<A#tota :7 < pub ic static 'oid Main9stringBC ar : 8 +a cu ator c;new +a cu ator9:7 c.1dd=umber9:7 c.>isp a6=umber9:7 < < < b. Destructor: - 1 >estructor has the same name as its c ass but is pre!ixed with a D # which is the s6mbo o! ti de. >estructors cannot be inherited or o'er oaded. e.g.: - using 56stem7 namespace ca c 8 c ass +a cu ator 8 static int num1#num2#tota 7 pub ic 'oid 1dd=umber9: 8 tota ;num1"num27 +onso e.0rite?ine9@3he 3ota is 8)<A#tota :7 < +a cu ator9: 8 num1;1)7 num2;2)7 tota ;)7 +onso e.0rite?ine9@+onstructor *n'oEedA:7 < D+a cu ator9: 8 +onso e.0rite?ine9@>estructor *n'oEedA:7 < pub ic static 'oid Main9stringBC ar : 8 +a cu ator c;new +a cu ator9:7 c.1dd=umber9:7 < << c. Static constructor: - 5tatic constructors are used to initia i4e the static 'ariab es o! a c ass. 2 3hese 'ariab es are created using the static Ee6word and the6 store 'a ues that can be shared b6 a the instances o! a c ass.2 3he constructors wi be in'oEed on 6 once during the execution o! a program.2 5tatic +onstructors ha'e an imp icit pri'ate access. e.g., $ pub ic c ass 5tatF+onstruct 8 static int num17 int num27 static 5tatF+onstruct 8 num1;1)7 num2;237 << >. 8ow does "3 s$&&orts inheritance? Ans: n 'E, nheritance is the property "y which the o"1ects of a derived class possess copies of the data mem"ers and the mem"er functions of the "ase class. Q + class that inherits or derives attri"utes from another class is called the derived class. Q The class from which attri"utes are derived is called the "ase class.Q n 'E, nheritance ena"les the easy maintenance of code. +ny change made to the "ase class automatically changes the "ehavior of its su"classes.Q The synta! used in 'E for creating derived classes is as follows: UaccessTspecifierW class U"aseTclassW H VV. L class UderivedTclassW : U"aseTclassW H VV. L 1@. What is method o,er oading? :i,e an e#am& e. Ans: 3ethod /verloading is the most common way of implementing polymorphism. $e can implement 3ethod overloading "y defining two or more functions in a class sharing the same name. e.g.: % using -ystemG namespace 'alculate3a! Hclass 'alculate3a! Hpu"lic int 3a!)int num1, int num=*H if )num1Wnum=*H return num1G L else H return num=G L L pu"lic float 3a!)float num1, float num=* H if)num1Wnum=* H return num1G L else H return num=G L L L class 3a!'alc H static int 3ain)* H'alculate3a! calInew 'alculate3a!)*G 'onsole.$riteLine);H>L<,cal.3a!)@.AF, Z.BF**G 'onsole.$riteLine);H>L<,cal.3a!)1[,1=**G 'onsole.(eadLine)*G return >G L L 11. What is o&erator o,er oading? :i,e an e#am& e. Ans: /perator overloading refers to loading an operator to perform different operations on different data types on different conte!ts. To overload an operator in a class, one defines a method "y using the

13

\operator\ keyword. /perator overloading allows user%defined types such as structures and classes, to use overloaded operators for easy manipulation of their o"1ects. /perator overloading can "e achieved "y defining the static mem"er functions using the operator keyword. using -ystemG pu"lic struct 'omple!+dd H pu"lic int rG pu"lic int imgG pu"lic 'omple!)int r, int img* H this.r I rG this.img I imgG L pu"lic static 'omple!+dd operator :)'omple!+dd c1, 'omple!+dd c=* H return new 'omple!+dd)c1.r : c=.r, c1.img : c=.img*G L pu"lic override string To-tring)* H return)-tring.Format)JH>L : H1LiJ, r, img**G L pu"lic static void 3ain)* H 'omple!+dd var1 I new 'omple!+dd)@,?*G 'omple! var= I new 'omple!)B,=*G 'omple!+dd total I var1 : var=G 'onsole.$riteLine)JFirst comple! num"er: H>LJ,var1*G 'onsole.$riteLine)J-econd comple! num"er: H>LJ,var=*G 'onsole.$riteLine)JThe sum of the two num"ers: H>LJ,total*G L L n this program uses operator overloading to create a comple! num"er class 'omple!+dd that defines comple! addition. The program displays imaginary and the real parts of the num"ers and the addition result using an override of the To-tring method.

Lesson: B 1. What is a &re&rocessor? What does the 3if6 3e se6 3e if6 3endif6 3define6 3$ndef6 3warning6 3error6 and 3 ine directi,es do? :i,e e#am& es for each. +ns: Pre&rocessor: $hile the compiler does not have a separate preprocessor, the directives are processed as if there was a preprocessor. These directives are used during conditional compilation. 4nlike ' and ':: directives, we cannot use these directives to create macros. + preprocessor directive must "e the only instruction on a line. 3if: %Eif, "egins a conditional directive for testing a sym"ol, to see if they evaluate to true. f they do evaluate to true, the compiler evaluates all the code "etween the Eif and the ne!t corresponding directive. The following operators can also "e used to evaluate multiple sym"ols, like: II )eDuality sym"ol*,YI )ineDuality sym"ol*, ]] )and sym"ol*, ^^ )or sym"ol* e.g.: %Edefine .E&4F Edefine ,'T,B using -ystemG pu"lic class 3y'lass H pu"lic static void 3ain)* H Eif ).E&4F ]] Y,'T,B* 'onsole.$riteLine)J.E&4F is definedJ*G Eelif )Y.E&4F ]] ,'T,B* 'onsole.$riteLine)J,'T,B is definedJ*G Eelif ).E&4F ]] ,'T,B* 'onsole.$riteLine)J.E&4F and ,'T,B are definedJ*G Eelse 'onsole.$riteLine)J.E&4F and ,'T,B are not definedJ*G Eendif L L 3e se: %Eelse, creates a compound conditional directive, such that, if none of the e!pressions in the preceding Eif or Eelif directives did not evaluate to true, the compiler will evaluate all code "etween Eelse and the su"seDuent Eendif. e.g.: %%Edefine .E&4F Edefine ,'T,B using -ystemG pu"lic class 3y'lass H pu"lic static void 3ain)* H Eif ).E&4F ]] Y,'T,B* 'onsole.$riteLine)J.E&4F is defined<*G Eelse 'onsole.$riteLine)J.E&4F and ,'T,B are not definedJ*G Eendif L L 3e if: % Eelif, creates a compound conditional directive. f Eelif e!pression will "e evaluated if neither the preceding Eif nor any preceding )optional* Eelif directive to true. f a Eelif e!pression evaluates to true, the compiler evaluates all the code "etween the Eelif and the ne!t corresponding directive. E.g.: -ame as up. 3endif : %Eendif specifies the end of a conditional directive, which "egan with the Eif directive. + conditional directive, "eginning with a Eif directive, must e!plicitly "e terminated with a Eendif directive. E.g.: -ame as up.

14

3define: %Edefine, defines a sym"ol "y using the sym"ol as the e!pression passed to the Eif directive, the e!pression will evaluate to true. E.g.: -ame as up. 3$ndef: % Eundef, undefines a sym"ol "y using the sym"ol as the e!pression in a Eif directive, the e!pression will evaluate to false. The Eundef directive must appear in the file "efore we use any statements that are not directives. e.g.: %Eundef .E&4F using -ystemG pu"lic class 3y'lass H pu"lic static void 3ain)* H Eif .E&4F 'onsole.$riteLine)J.E&4F is definedJ*G Eelse 'onsole.$riteLine)J.E&4F is not definedJ*G Eendif L L 3warning: %Ewarning, generates a level one warning from a specific location in our code. + common use of Ewarning is in a conditional directive . e.g.: % Edefine .E&4F pu"lic class 3y'lass H pu"lic static void 3ain)* H Eif .E&4F Ewarning .E&4F is defined Eendif L L 3error: % Eerror, generates an error from a specific location in your code. + common use of Eerror is in a conditional directive. e.g., $Edefine .E&4F pu"lic class 3y'lass H pu"lic static void 3ain)* H Eif .E&4F Eerror .E&4F is defined Eendif L L 3 ine: % Eline, modifies the compiler9s line num"er and the file name output for errors and warnings. + source code file may have any num"er of Eline directives. E.g.: %pu"lic class 3y'lass= H pu"lic static void 3ain)* H Eline =>> int iG Eline Z char cG LL 2. What is an e#ce&tion? 8ow e#ce&tions are hand ed in "3? +ns: +n e!ception is any error condition or une!pected "ehavior encountered "y a program in e!ecution. E!ceptions can "e raised "ecause of: i* Fault in the code or in shared li"rary. ii* 4navaila"ility of operating system resources. iii* 4ne!pected conditions encountered "y the 'L( encounters. E!ceptions are handled "y a try statement. $hen an e!ception occurs, the system searches for the nearest catch "lock that can handle the e!ception. /nce a matching catch "lock is found, the control is transferred to the first statement of the catch "lock and the catch "lock e!ecutes. f no matching catch "lock or finally "lock is found, then the e!ecution of the thread is terminated. e.g.: %77 this program shows an e!ception if a varia"le is divided "y #ero. using -ystemG class ThrowT+rithmeticTE!ceptions H int resG pu"lic ThrowT+rithmeticTE!ceptions)int n1, int n=* H try H res I n1 7 n=G 'onsole.$riteLine)Jresult is H>LJ , res*G L catch)+rithmeticE!ception e1* H 'onsole.$riteLine)JThe ,alue can not "e .ivided "y Pero M>N J : e1*G L Lstatic void 3ain)stringMN args* H ThrowT+rithmeticTE!ceptions sInew ThrowT+rithmeticTE!ceptions)1A, >*G 'onsole.(eadLine)*G LL 11. What is the $se of .(stem."o ections names&ace? Ans: The -ystem.'ollections namespace contains interfaces and classes that are used to define various collections of o"1ects, such as lists, Dueues, "it arrays, hashta"les and dictionaries. 6 Each class has a set of methods and properties, which are used on those corresponding class o"1ects. 3. What is an $nsafe code? E#& ain. +ns: Insafe "ode: % 4nsafe codes are the codes, where it is possi"le to declare and operate on pointers, to perform conversions "etween pointers and integral types, to take the address of varia"les, and so forth. n a sense, writing unsafe code is much like writing ' code within a 'E program. 6 4nsafe code is in fact a ;safe< feature from the perspective of "oth developers and users. 64nsafe code must "e clearly marked with the modifier unsafe, so developers can9t possi"ly use unsafe features accidentally, and the e!ecution engine works to ensure that unsafe code cannot "e e!ecuted in an untrusted environment. e.g.: %using -ystemG class Test H static void $riteLocations)"yteMN arr* H unsafe H fi!ed )"yte6 p+rray I arr* H "yte6 pele I p+rrayG for )int i I >G i U arr.LengthG i::* H "yte value I 6peleG 'onsole.$riteLine)JarrMH>LN at >!H1:2L is H=LJ, i, )uint*pele, value*G pele::G L L L L static void 3ain)* H "yteMN arr I new "yteMN H1, =, ?, A, @LG $riteLocations)arr*G L

15

%. What is threading? +ist o$t the ad,antages and disad,antages of m$ ti& e threads. +ns: Threading is defined as the e!ecution path of a program. Threads are used to run applications that perform large and comple! computations. Threads are the "asic unit to which an operating system allocates processor time, and more than one thread can run inside that process. Ad,antage of M$ ti& e threads: % 6'an communicate over a network, to a $e" server and to a data"ase. 6 0erform operations that take a large amount of time. 6 .istinguish tasks of varying priority. For e!ample, a high% priority thread manages time%critical tasks, and a low%priority thread performs other tasks. 6 +llow the user interface to remain responsive, while allocating time to "ackground tasks. 0isad,antage of M$ ti& e threads: % 63emory reDuirement for the conte!t information reDuired "y processes, +pplication .omain o"1ects, and threads. Therefore, the num"er of processes, +pplication .omain o"1ects, and threads which can "e created is limited "y memory availa"ility. 6 _eeping track of a large num"er of threads consumes significant processor time. f there are too many threads, then there will not "e any significant advantage of threads. 6 'ontrolling e!ecution of an application with many threads can "e a source of many "ugs and it is very comple!. *. Write a note in +i'rar( <ase " asses. +ns: The .NET Framework "ase classes include classes, interfaces, and value types that provide access to system functionality. 6To facilitate interopera"ility "etween languages, the .NET Framework "ase classes are 'L- compliant and therefore can "e used from any programming language. 6 The .NET Framework provides a rich set of interfaces, a"stract and concrete )non%a"stract* classes. 6 $e can use the concrete classes as is or can derive own classes from them. 6To use the functionality of an interface, we can either create a class that implements the interface or derive a class from one of the interface of .NET Framework classes. 6 NET Framework types use a dot ).* synta! naming scheme that is in a hierarchy. 6 These also include types that perform the following functions: a* (epresent "ase data types and e!ceptions "* Encapsulate data structures. c* 7/ operations d* +ccess information of types. e* .NET Framework security checks f* 0rovide data access, F4 , and $e" services. ). What is the ro e of .(stem.D'7ect6 .(stem..tring6 .(stem.Arra( and .(stem."o ections " asses? +ns: The roles of the various classes and namespaces are as follows: .(stem.D'7ect: % The -ystem./"1ect class provides classes and methods that allow us to "uild generic routines, provides Type -ystem 4nification, and ena"les working with groups collections. -ystem./"1ect class is ultimate "ase class that all types directly or indirectly derive from. .(stem..tring: % The -ystem.-tring class provides methods that allow us to perform various string operations. n 'E, a te!t string is stored in a data type named string, which is an alias to -ystem.-tring type. .(stem.Arra(: ! +rray types are reference types derived from the a"stract "ase type -ystem.+rray. The -ystem.+rray class provides methods for creating, traversing, and manipulating, sorting, and searching arrays. .(stem."o ections: % The -ystem.'ollections namespace contains interfaces and classes that define various collections of o"1ects, such as lists, Dueues, "it arrays, hash%ta"les and dictionaries. ?. What is 'o#ing and $n'o#ing? E#& ain with an e#am& e. +ns: <o#ing: % &o!ing refers to the conversion of value types to o"1ect types. &o!ing is an implicit conversion of a value type o"1ect or to any interface type implemented "y this value type. &o!ing a value of a value allocates an o"1ect instance and copies the value into the new o"1ect. e.g.: using
System; class TestBoxing { public static oi! "ain#$ { int i % &'(; ob)ect o % i; i % *+,; Console.-rite.ine#/T0e Console.-rite.ine#/T0e ob)ect1type alue % {23/4 o$; 33 alue1type alue % {23/4 i$;

In'o#ing:! 4n"o!ing refers to the conversion of o"1ect types to value types. 4n"o!ing is an e!plicit conversion from the type o"1ect to a value type or from reference type to a value type that implements the interface. +n un"o!ing operation consists of: % a. 'hecking the o"1ect instance to make sure it is a "o!ed value of the given value type. '. 'opying the value from the instance into the value%type varia"le. E.g.: using System;public class
5nboxingTest{ public static oi! "ain#$

16

{int int6 % &'(; ob)ect o % int6; try { int int7 % #int$o; Console.-rite.ine#/5nboxing 89./$; 3 catc0 #6n ali!CastException e${Console.-rite.ine#/{23 Error: 6ncorrect unboxing./4 e$;3 3 3

2. What are the different methods s$&&orted '( .(stem.D'7ect c ass? :i,e an e#am& e for each. +ns: Following are the different methods supported "y -ystem./"1ect: % a/ The EE$a s Method: This is a common operation, especially for searching and sorting in collections, it tests two o"1ects for eDuality. The EDuals method of the o"1ect class provides a default implementation that compares two reference type o"1ects for reference eDuality. The following code snippet shows the use of the EDuals method: e.g.: pu"lic static void 3ain)* Hstring str1I ;3ark<G string str=I ;+dam<G str?I ;3ark<G 'onsole.$riteLine)/"1ect.EDuals)str1,str=**G 77.isplays False 'onsole.$riteLine)/"1ect.EDuals)str1,str?**G 77.isplays True L '/ The 9eferenceEE$a s Method: the EDuals and (eferenceEDuals methods are semantically eDuivalent, e!cept that the (eferenceEDuals works only on o"1ect instances. This method compares o"1ect instances .The (eferenceEDuals method is static. E.g.: pu"lic static void 3ain)* H o"1ect o"11I nullG o"1ect o"1=I nullG 'onsole.$riteLine)/"1ect.(eferenceEDuals)o"11,o"1=**G 77.isplays True L c/ The To.tring Method: The purpose of the To-tring method is to return a string representation of a type. The default implementation in the o"1ect class returns a string with the name of the o"1ect. The To-tring method overrides To-tring in the o"1ect class. e.g.: % pu"lic class E!ample H void -tr'onvert)* H /"1ect o"1I new /"1ect)*G 'onsole.$riteLine)o"1.To-tring)**G 77.isplays -ystem./"1ect L L d/ The :etT(&e Method: FetType is the "asis for using reflection in .NET. t returns a Type o"1ect, descri"ing the o"1ect it was called on. This method returns a Type o"1ect, descri"ing the o"1ect it was called on. e.g.: pu"lic static void 3ain)*H 'lass1 o"1I new 'lass1)*G 'onsole.$riteLine)o"1.FetType)**G 77.isplays 'lass1 L e/ :et8ash"ode: This method makes any o"1ect usa"le in a hash ta"le or any hashing algorithm. The FetKash'ode method makes any o"1ect usa"le in a Kashta"le or any hashing algorithm. E.g.: pu"lic struct nt?= H pu"lic int valG pu"lic override int FetKash'ode)* H return valG 77(eturns an integer value L L f/ Mem'erwise" one: This method is used to create a "itwise copy of the type. $henever we need to create a "itwise copy )shallow copy* of our type, the 3em"erwise'lone method is used. E.g.: pu"lic static void 3ain)* H 'lass1 o"11I new 'lass1)*G o"11.nameI ;-tephen<G 'lass1 o"1= I )'lass1*o"11.3em"erwise'loneG L g/ Fina iKe: This method is used as a destructor. The Finali#e destructor is called after the last reference to an o"1ect is released from the memory. The .NET Framework automatically runs the Finali#e destructor to destroy o"1ects in the memory. The following code snippet illustrates how to override the Finali#e method: e.g.: `/"1ect)*G 1@. Write a note on the fo owing: a. .ing e!dimensiona arra(s: -ingle%dimension array is defined as an array having only one dimension. $e can declare a single%dimension array of five integers in the following way: intMN arr I new int M@NG This array contains the elements from arrM>N to arrMAN. The new operator is used to create the array and initiali#e the array elements to their default values. n this case, all the array elements are initiali#ed to #ero. +n array that stores string elements can "e declared in the same way. For e!ample: stringMN my-tring+rray I new stringMBNG '. M$ tidimensiona arra(s: 3ultidimensional array is defined as an array having more than one dimension. For e!ample, the following declaration creates a two%dimensional array of four rows and two columns: intM,N arr I new intMA,=NG The following code creates an array of three dimensions, A, =, and ?, as shown "elow: intM,,N arr I new int MA,=,?NG c. =agged Arra(s: + 1agged array is an array whose elements are arrays. The elements of a 1agged array can "e different dimension and si#es. + 1agged array is sometimes called an ;array%of%arrays<. e.g.: % using -ystemG

17

public class 7agge!;rrayTest { public static oi! "ain#$ { int<=<= my;rray % ne> int<'=<=; my;rray<2= % ne> int<+= { &4 (4 +4 ?4 @ 3; my;rray<&= % ne> int<*= { '4 *4 ,4 A 3; Bor #int i % 2; i C my;rray..engt0; iDD$ {Console.-rite#/Element#{23$: /4 i$; Bor #int ) % 2; ) C my;rray<i=..engt0; )DD$ Console.-rite#/{23{&3/4 my;rray<i=<)=4 ) %% #my;rray<i=..engt0 1 &$ E // : / /$;Console.-rite.ine#$; 3 3 3

d. Passing Arra(s Ising ref and o$t: Like all out parameters, an out parameter of an array type must "e assigned "efore it is usedG that is, it must "e assigned "y the caller. n case of ref parameters, a ref parameter of an array type must "e definitely assigned "y the caller. Therefore, there is no need to "e definitely assigned "y the caller. + ref parameter of an array type may "e altered as a result of the call. For e!ample, the array can "e assigned the null value or can "e initiali#ed to a different array.

e.g., $using System;class Passing;rray5singFGeBFan!F8ut{public static

oi! Hill;rray#reB int<=arr$ {iB #arr %% null$ arr % ne> int<&2=;arr<2= % &'(; arr<*= % &2'*;3static public oi! "ain#$ { int<= my;rray %{&4'4(4*4+3;Hill;rray#reB my;rray$; Console.-rite.ine#/;rray elements are:/$; Bor #int i % 2; i C my;rray..engt0; iDD$ Console.-rite.ine#my;rray<i=$;33

>. Write a &rogram to re& ace a ArB '( A9B in the string Lrose is a roseM. Ans: using -ystemG class 'hange'ase H static void 3ain)stringMN args* H string str I Jrose is a roseJG strIstr.(eplace)JrJ,J(J*G 'onsole.$riteLine)str*G 'onsole.(eadLine)*G L L +esson 2: 1. :i,e the o,era conce&t of A0D.NET with the he & of fig$res. Ans: +ctive2 .ata /"1ects for the .NET Framework )+./.NET* is a set of classes that provide data access services to the .NET programmer. +./.NET provides a rich set of components for creating distri"uted, data%sharing applications. t is an integral part of the .NET Framework, providing access to relational data"ase, 23L, and application data. +./.NET supports a variety of development needs, including the creation of front end data"ase clients and middle tier "usiness o"1ects used "y applications, tools, languages, or nternet "rowsers. +./.NET provides consistent access to data sources such as 3icrosoft -aL -erver, or data sources e!posed via /LE .& and 23L. .ata sharing applications can use +./.NET to connect to these data sources and retrieve, manipulate, and update data. The data residing in a data"ase is retrieved through data provider. .ifferent components of the data provider retrieve data from the data"ase, provide the data to the ,isual &asic .NET application, and update the data"ase with the changes made in the application. +n application can access data either through a dataset or through a .ata%(eader o"1ect: a/ Ising a dataset: n this case, the data is cached in a dataset and the application accesses the data from the dataset. '/ Ising a data reader: n this method, a .ata%(eader o"1ect, which is a component of the data provider, uses the 'onnection o"1ect to connect to the data"ase, uses the 'ommand o"1ect to retrieve data, and provides data to the application in a read%only and forward%only mode. +./ .NET also ena"les to create an 23L representation of a dataset. n an 23L representation of a dataset, data is written in 23L format, and dataset schema is written "y using the 23L -chema definition language )2-.*. 2. E#& ain in detai the A0D.NET architect$re. Ans: The +./.NET components have "een designed for easy access and manipulation of data. There are two central components of +./.NET, .ata-et and .NET .ata 0rovider. The +./.NET .ata-et is the core component of the disconnected architecture of +./.NET. The .ata-et is e!plicitly designed for data access independent of any data source. t can "e used with multiple and different data sources, used with 23L data, or used to manage data local to the application. The .ata-et contains a collection of one or more .ataTa"le o"1ects. The other core element of the +./.NET architecture is the .NET .ata 0rovider, whose components )'onnection, 'ommand, .ata(eader, and .ata+dapter* are

18

e!plicitly designed for data manipulation. The 'onnection o"1ect provides connectivity to a data source. The 'ommand o"1ect ena"les access to data"ase commands to return data, modify data, run stored procedures, and so on. The .ata(eader provides a high%performance stream of data from the data source. Finally, the .ata+dapter provides the "ridge "etween the .ata-et o"1ect and the data source. The .ata+dapter uses 'ommand o"1ects to e!ecute -aL commands at the data source to "oth load the .ata-et with data, and to update changes made to the data in the .ata-et "ack to the data source. 3. What is a data &ro,ider? E#& ain. +ns: + data provider is used for connecting to a data"ase, retrieving data, storing the data in a dataset, reading the retrieved data, and updating the data"ase. There are two types of data providers: a/ D+E 0< data &ro,ider: This type of data provider works with all the /LE .& providers, such as -aL /LE .& provider, /racle /LE .& provider, and 5et /LE .& provider. The /LE .& .ata provider classes are present in the -ystem..ata./le." namespace. '/ .N+ .er,er data &ro,ider: This type of data provider is used to work specifically with 3icrosoft -aL -erver. + -aL -erver data provider is recommended for working with a 3icrosoft -aL -erver data source, "ecause a -aL -erver data provider allows fast access to a data source without going through an /LE .& or /.&' layer. The -aL -erver data provider classes are present in the -ystem..ata.-Dl'lient namespace. The .NET data provider is designed to "e lightweight, creating a minimal layer "etween the data source and application code, increasing performance without sacrificing functionality. The four main components of .NET data provider: % 1* "onnection: Esta"lishes a connection to a specified data source. =* "ommand: E!ecutes a command against a data source. ?* 0ata 9eader: (eads a forward%only, read%only stream of data from a data source. A* 0ata Ada&ter: 0opulates a .ata-et and resolves updates with a data source.

%. What is a data set? E#& ain +ns: 0ataset: % The .ataset is a memory "ased relational representation of data. + .ataset is a part of the disconnected environment. + dataset is a disconnected, cached set of records that are retrieved from a data"ase. +./.NET supports scala"ility "y working with datasets. .ata"ase operations are performed on the dataset instead of on the data"ase. The dataset acts like a virtual data"ase containing ta"les, rows, and columns. +n application works with the data"ase records stored in the dataset. + .ataset is present in the .ataset class in the -ystem..ata namespace. The key components of a .ataset are : % 1* 0ataTa' e"o ection : ! t contains all the ta"les retrieved from the .atasource. =* 0ata9e ation"o ection : ! t contains relationship and links "etween ta"les in a .ataset. ?* 0ataTa' e : ! t represents a ta"le in the datata"le 'ollection of a dataset. A* 0ata9ow"o ection : ! t contains all the rows in a datata"le. @* 0ata"o $mn"o ection : ! t contains all the columns in a datata"le. *. Write a &rogram to show the demonstration of A0D.NET. Ans: using System; using System.Collections.Ieneric; using System.Text;
using System.Jata.SKlClient; namespace JemoF;J8FNET { class Program { static oi! "ain#string<= args$ {string connectionString % /Jata Source%NB"S9N;6nitial Catalog % ;! enture-orLs; 5ser i!%sa;Pass>or!%NB"S9NS/; string sSM. % /Select N Brom Employee/; SKlConnection cn % ne> SKlConnection#connectionString$; cn.8pen#$; SKlComman! cm! % ne> SKlComman!#sSM.4cn$; SKlJataGea!er !r % cm!.ExecuteGea!er#$; >0ile #!r.Gea!#$${Console.-rite.ine#!r<2=D//D!r<&=$; 3 cn.Close#$;Console.Gea!.ine#$;333

+esson ?: 1. What is a we' ser,ice? E#& ain its working. +ns: $e" -ervice: % + $e" service is a very simple idea. t is application logic, accessi"le through some standard $e" protocol.

1(

6+ $e" service is 1ust "etween computer to computer applications. 6 t is like a program on one computer calling a method that e!ists on another computer and calling it through the nternet.6 + $e" service does not have user interface. + $e" service is designed to interact with applications.6 $e" service or 23L we" service is 1ust a collection of methods that can "e called from some other computer, from a remote location. The cloud in the middle of figure is the nternet. 6 The result goes "ack to the consumer. To the consumer there is very little difference from calling a method that is running on the same machine, "ut it is running at some other location on the nternet.

2. 8ow does the we' ser,ice differ from we' &age? Ans: Following are the differences "etween $e" 0ages ] $e" -ervices: % We' Page: % + $e" page has a user interface. That is main part of it. The $e" page, since it has a user interface, it interacts with users. /n the $e"%page side, naturally, a $e" "rowser is the client. We' .er,ice: % + $e" service does not have user interface. + $e" service is 1ust "etween computer to computer applications. t is like a program on one computer calling a method that e!ists on another computer and calling it through the nternet. + $e" service is designed to interact with applications. t is code that is going to call my $e" service, not some user "y clicking some "utton. /n the $e"%service side, the client can "e anything that can seriali#e a reDuest and de%seriali#e the result that comes "ack. /n the $e"%service side , its work any type of the client. %. What is A.P.NET? Ans: +-0.NET is an entirely new paradigm for server%side +-0 scripting. +-0.NET is a unified $e" development platform that provides the services necessary for us to "uild enterprise $e" applications. +-0.NET is largely synta! compati"le with +ctive -erver 0agesG it also provides a new programming model and infrastructure that allow us to create secure, scala"le, sta"le and powerful applications. +-0.NET is a compiled, .NET%"ased environmentG and allows us to take full advantage of the features of the 'L(, such as type safety, inheritance, language interopera"ility and versioning. +-0.NET has "een designed to work with ;$hat Oou -ee s $hat Oou Fet< )$O- $OF* KT3L editors and other programming tools, including 3icrosoft ,isual -tudio .NET. 3. With a neat diagram e#& ain the e,ent hand ing &rocess of win formsOwe' forms.

COP Page .anguage%/C#/ ;utoE ent-ireup%/true/ Co!eHile%/JeBault.aspx.cs/ 6n0erits%/FJeBault/OQ CRJ8CTSPE 0tml P5B.6C /1//-(C//JTJ TUT". &.2 Transitional//EN/ 0ttp://>>>.>(.org/TG/x0tml&/JTJ/x0tml&1transitional.!t!/Q C0tmlQC0ea!QC/0ea!QCscript language%/C#/ runat%/ser er/Q oi! SubmitBtnFClicL#8b)ect sen!er4 E ent;rgs e${"essage.Text % /Ui / D Uttp5tility.UtmlEnco!e#Name.Text$ D /4 T0anLsRRRRR Sou 0a e Selecte!: / D Category.Selecte!6tem;3VC/scriptQCbo!yQCcenterQCBorm action%/JeBault.aspx/ met0o!%/post/ runat%/ser er/QC0(Q Name: Casp:textbox i!%/Name/ runat%/ser er//Q

2)

Category: Casp:!rop!o>nlist i!%/Category/ runat%/ser er/QCasp:listitemQT8SSC/asp:listitemQ Casp:listitemQSP8GTS 96TC/asp:listitemQCasp:listitemQH.8-EGSC/asp:listitemQC/asp:!rop!o>nlistQ C/0(QCasp:button text%/.ooLup/ 8nClicL%/SubmitBtnFClicL/ runat%/ser er//Q Casp:label i!%/"essage/ runat%/ser er//QC/BormQC/centerQC/bo!yQC/0tmlQ

Each +-0.NET server control is capa"le of e!posing an o"1ect model containing properties, methods and events. +-0.NET developers can use such o"1ect model to cleanly modify and interact with the page.6 The a"ove mentioned e!ample demonstrates how an +-0.NET page developer can handle the /n'lick event from the Uasp:"utton runatIJserverJW control to manipulate the te!t property of the Uasp:la"el runatIJserverJ7W control.6 n this e!ample, when this we" form loads on the we" "rowser, there is two La"el, one Te!t"o!, one .rop.ownList, one &utton.6 $hen the 4-E( select any item present in the .rop.ownList and click on the &utton, it displays a message along with the name and the selected item from the dropdownlist. 6This event occurs due to +-0.NET server controls which handle it. *. What is the $se of A.P.NET? Ans: +-0.NET is precompiled code so it "ecomes very easy to use it in we" applications development. $e can easily use the "enefits of these technologies, which include managed 'L( environment, type safety, nheritance, language interopera"ility and versioning. +-0.NET provides a new programming model and infrastructure for more secure, scala"le, and sta"le applications. $e can write applications in any .NET compati"le language, including ,&.NET, 'E, and 5-cript .NET. .evelopers can easily use the "enefits of these technologies, which include the managed 'L( environment, type safety, inheritance, and so on. ). Write a &rogram to dis& a( LWe come to A.P.NETM ? times in increasing order of their font siKe $sing A.P.NET.

Ans:

COP Page .anguage%/C#/ ;utoE ent-ireup%/true/ Co!eHile%/JeBault.aspx.cs/ 6n0erits%/FJeBault/ OQ CRJ8CTSPE 0tml P5B.6C /1//-(C//JTJ TUT". &.2 Transitional//EN/ /0ttp://>>>.>(.org/TG/x0tml&/JTJ/x0tml&1transitional.!t!/Q C0tml xmlns%/0ttp://>>>.>(.org/&@@@/x0tml/ Q C0ea! runat%/ser er/QCtitleQ5ntitle! Page C/titleQC/0ea!QCbo!yQCcenterQCBorm i!%/Borm&/ runat%/ser er/Q C!i Q COBor #int i%2; iCA;iDD${OQ CBont siWe%/CO%iOQ/Q-elcome to t0e ;SP .NETC/BontQCbr /Q CO3OQ C/!i Q C/BormQ C/centerQC/bo!yQC/0tmlQ

2. What is the ro e of .(stem.We'? Ans: The -ystem.$e" namespace supplies classes and interfaces that ena"le "rowser and server communication. This namespace includes the Kttp(eDuest class that provides e!tensive information a"out the current KTT0 reDuest, the Kttp(esponse class that manages KTT0 output to the client, and the Kttp-erver4tility class that provides access to server%side utilities and processes. -ystem.$e" also includes classes for cookie manipulation, file transfer, e!ception information, and output cache control. ?. Write a &rogram to demonstrate hand ing of ser,er contro e,ents. Ans: COP Page .anguage%/C#/ ;utoE ent-ireup%/true/ Co!eHile%/JeBault.aspx.cs/
6n0erits%/FJeBault/ OQCRJ8CTSPE 0tml P5B.6C /1//-(C//JTJ TUT". &.2 Transitional//EN/ /0ttp://>>>.>(.org/TG/x0tml&/JTJ/x0tml&1transitional.!t!/QC0tmlQC0ea!QC/0ea!Q Cscript language%/C#/ runat%/ser er/Q oi! SubmitBtnFClicL#8b)ect sen!er4 E ent;rgs e${ "essage.Text % /Ui / D Uttp5tility.UtmlEnco!e#Name.Text$ D /4 T0anLsRRRRR Sou 0a e Selecte!: / D Category.Selecte!6tem; 3C/scriptQCbo!yQCcenterQCBorm action%/JeBault.aspx/ met0o!%/post/ runat%/ser er/Q C0(Q Name: Casp:textbox i!%/Name/ runat%/ser er//Q Category: Casp:!rop!o>nlist i!%/Category/ runat%/ser er/QCasp:listitemQT8SSC/asp:listitemQ Casp:listitemQSP8GTS 96TC/asp:listitemQCasp:listitemQH.8-EGSC/asp:listitemQC/asp:!rop!o>nlistQC/0(Q Casp:button text%/.ooLup/ 8nClicL%/SubmitBtnFClicL/ runat%/ser er//Q Casp:label i!%/"essage/ runat%/ser er//QC/BormQC/centerQC/bo!yQC/0tmlQ

Lesson [: 1. What is .NET 9emoting? Ans: (emoting is the process of communication "etween different processes, regardless of whether they are on the same or different computers. The .NET remoting system is an architecture designed to simplify communication "etween o"1ects e!isting in different application domains whether or not on the same computer. t also simplifies communication "etween different conte!ts whether or not in the same application domain. t can also use 23L encoding when interopera"ility with other remoting

21

systems is essential. (emoting was designed with security in mind, so we can seriali#e streams in order to secure them "efore they are transported over the channel.
2. 8ow is .NET 9emoting different from We' ser,ices and 0"DM? Ans: The differences "etween .NET (emoting and $e" services are listed as follows: +-0.NET "ased $e" services can only "e accessed over KTT0, whereas the .NET (emoting can "e used across protocol. $e" services work in a stateless environment where each reDuest results in a new o"1ect created to service the reDuest. .NET (emoting supports state management options and can identify multiple calls from the same client. $e" services seriali#e o"1ects through 23L contained in the -/+0 messages and can thus only handle items that can "e fully e!pressed in 23L. .NET (emoting relies on the life of the metadata within assem"lies that contain information a"out data types. This limited metadata information is passed a"out an o"1ect, when it is passed "y reference. $e" services support interopera"ility across platforms and are good for heterogeneous environments. .NET (emoting reDuires the clients to "e "y "uilt using .NET, which means a homogeneous environment. The difference 'etween .NET 9emoting and 0"DM is isted as fo ows: .'/3 relies on a proprietary "inary protocol that not all o"1ect models support. t also wants to communicate over a range of ports that are typically "locked "y firewalls. Kowever, .NET (emoting supports different transport protocol formats and communication protocols. This allows .NET (emoting to "e adapta"le to the network environment in which it is "eing used. 3. E#& ain remoting architect$re. Ans: The remoting architecture consists of the remote component, server, client, and a transportation medium that ena"les communication "etween the client and the server. These com&onents are e#& ained 'e ow. The remote component is the o"1ect that provides services to the client. The server creates and register a channel, which is a transportation medium, to listen at a specified port. The server also registers the remote o"1ect. + channel is a transportation medium through which communication "etween a server and a client takes place. The client reDuests for the services of a remote o"1ect. + client can choose the registered channels on the server to communicate with the remote o"1ect. NET remoting system, the com"ination of underlying technologies reDuired to open a network connection and use a particular protocol to send the "ytes to the receiving application are represented as a transport channel. A. With a neat diagram e#& ain the remoting &rocess. Ans: -uppose we have an application running on one computer, and we want to use the functionality that is stored on another computer. The a"ove state shows the general remoting process. $hen "oth the server and client are configured properly, a client creates a new instance of the server class. The remoting system creates a pro!y o"1ect that represents the class and returns to the client o"1ect a reference to the pro!y. $hen a client calls a method, the remoting system checks the type information, and sends the call over the channel to the server process. + listening channel picks up the reDuest and forwards it to the server remoting system, which locates and calls the reDuested o"1ect. The process is then reversed, as the server remoting system "undles the response into a message and the server channel sends to the client channel. Finally, the client remoting system returns the result of the call to the client o"1ect through the pro!y. *. E#& ain the ste&s or &hases in,o ,ed in im& ementing .NET remoting a&& ications.

22

Ans: The phases involved in implementing .NET remoting applications are: 1* 'reate a remota"le o"1ect: + remota"le o"1ect is an o"1ect that inherits from 3arshal&y(ef/"1ect. 2/ 'reate a server to e!pose the remote o"1ect: + server o"1ect acts as a listener to accept remote o"1ect reDuests. 3/ 'reate a client to use the remote o"1ect: + client o"1ect will connect to the server, create an instance of the o"1ect using the server, and then e!ecute the remote methods. ). Write a &rogram to dis& a( L8e o Wor dM string to demonstrate .NET remoting. Ans: using System; using System.Guntime.Gemoting; using System.Guntime.Gemoting.C0annels;
using System.Guntime.Gemoting.C0annels.Tcp; namespace Gemoting { public class Sample8b)ect : "ars0alByGeB8b)ect { public Sample8b)ect#$ public string Uello-orl!#$ { return /Uello -orl!R/; 3 3 3 {3

23

Vous aimerez peut-être aussi