61(Finish)

Embed Size (px)

Citation preview

  • 8/13/2019 61(Finish)

    1/23

    Lesson: 1.1. What is .NET Framework?Ans:The .NET Framework is the foundation on which we can design, develop, and deploy applicatiot is the core of the .NET infrastructure. t e!ists as a layer "etween the .NET applications and underlying operating system. The .NET Framework summari#es much of the "asic functionality, suchde"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 reo the presentation layer of an application. $e" forms are used in $e"%"ased applications, wher

    $indows Forms are used in $indows%"ased applications for providing an interactive user interfaceaddition, we can create character%"ased console applications that can "e e!ecuted from the commne. &esides these three components, the .NET Framework consists of two other components, thahe .NET Framework &ase 'lasses and the 'ommon Language (untime )'L(* .

    3. Write short notes on:+ns: .Net Framework comprised of following things: %Programming Methodoogies : The isual -tudio .NET programming methodology allows for mi!anguage programming. This is esta"lished through a 'ommon Type -ystem )'T-* that is defined forhe languages that .NET Framework supports. +ll these languages compile into an intermedanguage "efore they compile in native code. Therefore, the .NET developer has the independencecode one module of an application in one language and the other module of the same application

    another language.Patform Technoogies : ! The .NET Framework includes platform technologies like +/.N+-0.NET, and &.NET. +/.NET allows .NET applications to communicate with a data"ase for retrievaccessing, and updating data. +-0.NET is a framework for "uilding enterprise%class $e" applicatio&.NET is an o"ect%oriented language that provides features such as a"straction, encapsulation, apolymorphism. &y using these technologies, we can easily develop ro"ust $e" applications, $indoapplications, and 23L $e" services."ode E#ec$tion : !The code e!ecution process involves the conversion of ntermediate Language native or'04%specific code. The 'L( is completely architecture%neutral. +ll the .NET languages get compiled ihe L. This intermediate language gets compiled "y 5ust%in%Time )5T* compiler into the native mach

    code. +fter translating the L into native code, the converted code is sent to the .NET runtime manag

    The .NET runtime manager e!ecutes the code. $hile e!ecuting the code, a security check is performo ensure that the code has the appropriate permissions for accessing the availa"le resources.

    %. Which are the Patform technoogies s$&&orted '( .NET framework?+ns: -ome of the platform technologies supported "y .NET Framework are: 6+/.NET 6+-0.&.NET. 6+/ .Net is the technology that is used to access the data"ases. .Net has improved that k

    of programming significantly from an ease%of%use standpoint, through some features. The net effec+/ .Net for the developer has greatly simplified and enhanced capa"ility of programming wdata"ases. 6nternet was the certainly one of the keystone of the development of .Net, we understand from the name. The particular part of the technology, which deals with nternet, is ca+-0 .Net. The idea for developing s7w for the nternet can "e tricky. t "ecomes trickier, if we are tryo have reasona"le amount of programming logic sitting "ehind a we" page. 6+nother place where .

    has innovated is in 84ser nterface esigning9. t was started in the world of isual &asic. 6n ',struggle with hacking code to position our "uttons and our te!t "o!es, where as the isual "asic uwere ust dragging them on the screen and putting them where they wanted them. 6That9s the "eaof the tools that 3icrosoft has "uilt, that work with those languages. 6The $indow programs under .Net, which are designed visually, are called ;$in%Forms

  • 8/13/2019 61(Finish)

    2/23

    +ns: &ackward compati"ility refers to the a"ility of a technology to work with its previous versionwith other earlier technologies. For e!ample, the +ctive irectory structure of $indows =>>>"ackward compati"le with $indows NT ?.@1 and A.>. -imilarly, the .NET Framework supports "ackwcompati"ility. t is capa"le of running applications developed in isual -tudio on isual -tudio .Net. 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. "onsistent Programming Mode: % Every programming language has different approaches

    doing a task. 66For e!ample, accessing data with a & application and a ' application is totdifferent. + developer has to know "oth different techniDues to do the task. 6The .NET 'lass Li"rprovides the functionality to all .NET languages resulting in a consistent o"ect model regardless of programming language used "y the developer.. +ang$age -nde&endence : % Language ndependence means the developer has the freedom

    code one module of an application in one language and other module of same application in otanguage. 6This language interopera"ility can help in code reuse and improve the efficiency of development process.ii. No ,ersioning Pro'em :% t makes deployment of applications very easy. 6The .NET ensures tall the components the application depends on are availa"le on the computer "efore the applicat"egins to run.v. -m&ro,ed ec$rit( :% The .NET Framework provides several mechanisms for protecting resour

    and code from unauthori#ed users: 66a./+-0.NET $e" +pplication -ecurity provides a way to conaccess to a we" site "y comparing authenticated permissions with File -ystem permissions for proauthori#ation. './ 'ode access security uses permissions to control the code accessing protecesources and operations. c./ (ole%"ased security provides information needed to make decisi

    a"out user9s permissions.v. $&&ort for We' er,ices :% $ith the advent of .NET technology, we" services provide many "n &ase 'lass li"rary facilities, which open up a whole new world of information for users. 6$e" servican provide everything from "asic te!t news information to vital data"ase or application informationvi. 0(namic We' :% ynamic we" content is easier to create with .NET. +-0.NET and isual -tudio.Nallow developers to create dynamic we" much easier than - and +-0 technologies.vii. is$a t$dio .NET :%isual -tudio .NET is the 3icrosoft application and interface for programmn .NET isual -tudio.6This development environment has e!tensive set of ready to use controls, g

    de"ugging facilities, easy and simple programming features and vast set of .NET &ase 'lasses.

    . 0oes .NET &atform s$&&ort 'ackward com&ati'iit(? E#&ain.+ns: The .NET platform supports "ackward compati"ility. t is possi"le for an application compiledone version of the .NET Framework to run on a different version of the .NET Framework. For e!ampwe 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 Framewwe need to include the following line at the "eginning of the code: $sing 4mscori'.d

    & applications can work on &.NET and +-0 applications can run on +-0.NET "ecause"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.

    2

  • 8/13/2019 61(Finish)

    3/23

  • 8/13/2019 61(Finish)

    4/23

    A. E!ecuting code: The 'L( provides the environment that ena"les e!ecution as well as a varietservices that can "e used during e!ecution.

    . 8ow the .NET e#ec$tion en,ironment with a&&ication domain differs from traditiona wof e#ec$tion?Ans: .NET e#ec$tion en,ironment differs from traditiona wa( of e#ec$tion in foowmanners:

    a* f we are writing application in ' compiler or writing in isi"le &asic, we need a isual &acompiler, even for ', we need a ' compiler. &ut in .Net e!ecution environment, approach taken here is that all of those compilers compile into this same intermediate languag

    "* 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 santermediate language.

    d* 5ust%n%Time compiler only needs to understands one language, not all of them,. t only needunderstand 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 foowings:!"ommon T(&e (stem ;"T/ ! This is a standardi#ed agreed set of "asic data types. This systprovides a way for language interopera"ility. Language nteropera"ility means that an o"mplemented in one language can call a o"ect implemented in another language. n more general wyou can say that an application can "e developed in two or more languages supported "y .ramework. 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 "defined to enhance and ensure language interopera"ility is called the 'ommon Language -pecificat'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 undamental principle of the runtime. The responsi"ility of runtime is to load the code, run the code a

    provide all kinds of services. The services provided "y .NET (untime are as memory managemehread 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 camanaged code. 3anaged code is one, which is designed to run on .Net environment. The code whuns in windows environment is unmanaged code.ntermediate +ang$age ;-+/ % This is also called as 3icrosoft ntermediate Language )3-L*. ntermediate language is analogous to the "yte code of 5ava. The significant difference is that the "code in interpreted while the L is compiled "y 5T compilation to native machine code. The L codenot the machine code. The .Net (untime calls the 5ust%in%Time )5T* compiler to get native machine crom L code. This feature makes the .NET platform independent.NET

  • 8/13/2019 61(Finish)

    5/23

    A&&ication 0omain ! + "oundary that the common language runtime esta"lishes around o"ecreated within the same application is "y means of +pplication omain. +pplication domain allodifferent code to run in the same process space. ar'age "oection !The ar"age 'ollector frhe application from the responsi"ility of freeing memory when no longer reDuired. 'L( calls ar"a

    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 ametadata. 3etadata gives details of the assem"ly, properties and methods stored in it, secunformation etc.

    +ssem"lies can "e static or dynamic.tatic assem'iescan include .NET types )interfaces and classes*, as well as reDuired resourceshe assem"ly )"itmaps, 50E files, resource files, and so on*. -tatic assem"lies are stored on disk iniles.0(namic assem'iesare one, which run directly from memory and are not saved to disk "efe!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* writteone language could get used in another module, which is written in another language. The solutcame in the form of '/3 components are: 6The .Net Framework makes language interoperation eeasier "y allowing compilers to put additional information into all compiled modules and assem"l

    This information is called 3etadata. 63etadata is "inary information descri"ing the program. $hencompile our code into 0E file, metadata is inserted into one portion of the 0E file, while the codeconverted to L and inserted into another portion of the 0E file. 6Every type, mem"er, which are defior referenced in a module, is descri"ed within metadata. $hen code is e!ecutedG the runtime lometadata into memory and refers it to get information a"out the codes class, mem"ers, anheritance and so on. 63etadata allows .NET languages to descri"e themselves in a language%neumanner. 6t gives reDuired information to 'L( to perform much of its functionalities. 6The presenmetadata makes the assem"ly -elf%descri"ing file. 6The 'L( modules or components or otassem"lies, which want to communicate with each other users, these information stored in metadatperform their tasks. 6t stores information like: % a/ escription of the assem"ly9s operation.+ssem"ly dentity. c/ E!ported types. d/ /ther dependent assem"lies. e/ -ecurity permissionsescription of types. g/ 3em"ers like methods, fields, properties, events, nested types, etc.

    +ttri"utes.

    . What is the f$nction of "T? E#&ain the cassification of t(&es in "T with a diagram.Ans:The 'ommon Type -ystem )'T-* defines how types are declared, used and managed in untime. 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 hperformance code e!ecution.

    =* 0rovides an o"ect%oriented model.?* efines rules that languages must follow, so that different languages can interact with e

    other."assifications of t(&es in "T are as foows:

    1. a$e t(&es 2. 9eference t(&es

    5

  • 8/13/2019 61(Finish)

    6/23

    a* alue types directly stores data invaria"le. alue types can "e "uiltype, user%defined types, enumerations.

    "* (eference types store a reference to the data9s memory address. (eference types can "e descri"ing types, pointer types, or interface types. -elf%descri"ing types are further split iarrays and class types.

    c* The class types are user%defined classes, "o!ed value types, and delegates.d* +ll types derive from the -ystem. /"ect "ase types.

    1@. -t is tod that if we earn an( one .NET ang$age6 then working with other .Nang$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 .NETanguages 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 thesystem 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 opalJGsw1.$riteLine)tempstring*G

    sw1.'lose)*G -tream(eader sr1Inew -tream(eader)Jtemp.t!tJ*G string

    ilestringIsr1.(eadToEnd)*G sr1.'lose)*G'onsole.$riteLine)filestring*G // 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, thiopalJ

    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 synt

    and use of -tream(eader, -tream$riter, and the 'onsole class are identical, same methods, anddentical parameters.

    Lesson: 3.

    1. +ist o$t the im&ortant feat$res of "?Ans:-m&ortant feat$res of " are:' is a stylish, simple, type%safe, o"ect%oriented language.

    ' has the a"ility to "uild ro"ust system%level components due to following features: 66 '/370latform support for e!isting code integration. 66(o"ustness through gar"age collection and tsafety. 66-ecurity provided through good design. 66Full support of e!tensi"le metadata concepts.' supports Language nteropera"ility and 0latform ndependence due to following features: 66nteropera"ility with '/3 and .NET Framework services, through tight .NET Li"rary &ase classes23L support for we"%"ased component interaction. 66ersiona"ility.

    6

  • 8/13/2019 61(Finish)

    7/23

  • 8/13/2019 61(Finish)

    8/23

    another.The deegate t(&e:elegates are roughly similar to function pointers in ', "ut they

    ype%safe and secure.0reprocessor directives are used for conditional compilation. No header f

    are used in '.' operators: ' supports additional operators such as is and type of. t a

    ntroduces different functionality of some logical operators.The 3ain method is declared differe

    rom the main function in '. The usages of the command%line arguments are also differenMethod &arameters:' supports ref and out parameters, which are used instead of pointerpassing parameters "y reference.0ointers are allowed in ' "ut only in unsafe mode./verload

    operators is performed differently in '.trings:' strings are different from ' strings.

    oreach keyword allows you to iterate through arrays and collections.No glo"al methods or varia"

    n ': 3ethods and varia"les must "e contained within a type declaration.No header files or include directives in ': The using directive is used to reference types in ot

    namespaces without fully Dualifying the type names. 0estr$ctors: n ', you don9t have conover when a destructor is called "ecause destructors are called automatically "y the gar"collector. "onstr$ctors: 4nlike ', if you don9t provide a class constructor in ', a defconstructor is automatically generated for you. The default constructor initiali#es all the fields to tdefault values.' does not support "it fields.

    Lesson: %1. Which are two different categories of t(&e in "?+ns: There are two different categories of type in ' are C Gi.H a$e t(&e Gii.H 9eference t(&e.1/ a$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 creaa 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 thvaria"les, which are stored in memory. Q 4sing more than one varia"les, we can use reference typesefer 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"ect of other derived type.Q +ssignmeo a reference type varia"le, copies the address of o"ect.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 "? 0efine each.Ans:+ varia"le is a location in the memory that has a name and contains a value. The alue could

    an integer, decimal, character, string. + varia"le is associated with a data type that defines the typedata, which can "e stored in a varia"le. aria"les can "e initially assigned or initially not assigned.' varia"les are categori#ed in R categories they are:/ tatic ,aria'es: !+ varia"le declared with the static modifier is called a static varia"le. There

    "e only one copy of the varia"le, regardless of how many instances of class are created. ii/ -nsta,aria'es: ! + varia"les declared without the static modifiers are instance varia"les. iii/ Areements: !The array is a container that has a list of storage locations for a specified type. Telements for a specified type of an array come into e!istence when an array instance is created, e!ist until there are no references to that array instance. i,/ a$e &arameters: !0arameters arguments passed to the function. + parameter declared without a ref or out modifier is a vaparameter. + value parameter e!ists until the function returns. v* 9eference &arameters: parameter declared with a ref modifier is a reference parameter. + reference parameter does create a new instance, it points to the same storage location of the parameter passed as an argume,i/ D$t&$t &arameters: !+ parameter declared with an out modifier is an output parameteeference parameter does not create a new instance, it points to the same storage location of

    parameter passed as an argument. &ut output parameter must "e definitely assigned "efore unction returns. ,ii/ +oca ,aria'es: !+ local varia"le is declared and e!its within a "lock,

    statement, switch% statement, using statement. + local varia"le is not automatically initiali#ed, thus no default value.

    3. What is the im&ortance of a$tomatic memor( management? E#&ain with e#am&e?

    8

  • 8/13/2019 61(Finish)

    9/23

    Ans:n earlier days, developers need to manage the allocation and de%allocation of "locks of memowhich is known as 3anual memory management. 3anual memory management can "e "oth timconsuming and difficult.Q &ut in .NET Framework, 'L( provides a run%time environment, which manages the e!ecution of cand provides essential services like +utomatic memory management. Q +utomatic memmanagement eliminates memory leaks as well as some other common programming errors. Q n automatic memory management is provided so that developers are freed from this "urdensome task+utomatic memory management increases code Duality and enhances developer productivity withnegative impact on either e!pressiveness or performance.

    %. Write a note on e#&ression and o&erators in ".+ns: E#&ression:% +n e!pression is a seDuence of operators and operands that specifies computatand assigns the result to a varia"le. E!pressions are constructed from operands and operators. Toperators of an e!pression indicate which operations to perform. Exampes !or operators are "# $# %# Exampes !or operands are iteras# 'ariabes# and expressions.D&erators:% There are three types of operators 4nary, &inary, Ternary. +pplication use operatorprocess the data entered "y a user. /perators like and C are used to process varia"les and returvalue. +n operator is a set of one or more characters that is used for computations or compariso/perator can transform one or more data values, called operands, into a new data value. -oe!amples of /perators are +rithmetic, +rithmetic +ssignment, 4nary, 'omparison, Logical operators

    *. What are em&t( statement and a'eed statements? Wh( are the( $sed?

    Ans:Em&t( statement: !+n empty statement )S* simply transfers control to the end point of statement. t is used when there are no operations to perform, "ut reDuire a statement. +n emstatement can "e used when writing a while statement with a null "ody and can also "e used to decla la"el ust "efore the closing ;< of a "lock.+a'eed statement: !+ la"eled statement is prefi!ed "y a la"el. La"eled statements are permitte"locks. + la"el is a name given "y the identifier. The scope of a la"el is the "lock in which the la"edeclared. f two la"els have same name we get compile time error. + la"el can "e referenced from gstatements 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 iteratidepends on the condition represented "y &oolean e!pression. Q The "lock of code will "e iterated u

    he condition is true.Foreach statement: C + foreach statement lets us iterate over the elements in arrays collections.Q The elements of single%dimensional arrays are traversed in increasing order of indstarting with inde! > to Length%1.Q The elements of multi%dimensional arrays elements are traversuch that the indices of the rightmost dimension are incremented first, then the ne!t left dimensand so on to the left.Q Following e!ample uses a foreach statement to iterate over the elements ofarray Cusing -ystemG class ForEachE!ample H static void 3ain )* H intM arr Inew intM H1,=,?oreach )int i in arr*

    'onsole.$riteLine );alue is H>

  • 8/13/2019 61(Finish)

    10/23

    Ans:+ock tatements: !The lock statement o"tains the mutual e!clusion lock for a given o"ect,e!ecutes statements, and then releases the lock. The e!ample is shown "elow Ce.g.: % static void 3aH + a I ...G lock)a* H a.0 I a.0 1G

    Ising tatements: !The using statement o"tains one or more resources, e!ecutes statementand then releases of the resource. e.g.: % static void 3ain)* H using )(esource r I new(esource)** H r.Func)*G

    . Which are different 7$m& statements s$&&orted '( "?Ans:ifferent ump statements supported "y ' are: %1/ G while )trH if )iIIar.Length*

    "reakG 'onsole.$riteLine )arMi*G 2/ "ontin$e tatements: ! The continue statement is used to skip all the su"seDuent instructiand take the control "ack to the loop.e.g.: % using -ystemG class E!'ontinue H static void 3ain )stringM ar* Hint iI>G wtrue* H

    'onsole.$riteLine )arMi*G if )i U ar.Length* continueG "reakG 3/ 9et$rn tatement: !3ethods can either return a type or not. + method that does not returype must give its return type as 8void9. + method that does return a type must name the tyeturned. + method will stop e!ecuting and return a value when it reaches a 8return9 statement at a

    point in its e!ecution. The type returned is given at the end of such a return statementG its type mcorrespond with the type specified in the method declaration. For e!ample, the following piece of colustrates this point.

    e.g.: % using -ystemG class E!(eturn H static int add )int a, int "* H return a"G stavoid 3ain )* H'onsole.$riteLine )add)1,=**G returnG %/Throw tatement: !$e can throw an o"ect if the o"ect is either directly or indirectly derirom -ystem.E!ception. $e can use throw statement in the catch "lock to throw the present o"ect

    we can also throw a new e!ception of a different type. + throw without any e!pression can only "e un 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 govestatements that are enclosed within it and defines the scope of the e!ception handlers associated w

    t. f an e!ception occurs within the try "lock, an appropriate e!ception handler that is associated whe try "lock handles the e!ception.e.g.: % using -ystemG class E!ThrowTryH static int F )int a, int "* H if )"II>*hrow new e!ception );ivided "y Pero

  • 8/13/2019 61(Finish)

    11/23

    string 0 HgetG setG pu"lic delegate void EventKandler )o"ect sendEvent+rgs*G

    12. What is deegate? 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 referecan "e changed at runtime, as desired.Q elegates in ' allow us to dynamically change the refereo the methods in a class.Q elegates are primarily used in ' programming for implementing eve

    and the call%"ack methods.Q There are three steps in defining and using delegates: declaratnstantiation and invocation.e.g.: % First declare a delegate "y following synta! C delegate void -impleelegate)*G us

    -ystemG class TestH static void F)* H 'onsole.$riteLine);Test.F

  • 8/13/2019 61(Finish)

    12/23

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

    3. i,e an e#am&e of fied mem'er.Ans: + field is a mem"er that represents a varia"le associated with an o"ect or class.Q The fields nitiali#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 ushgreen0artGpu"lic 'olor)ushort red, ushort "lue, ushort green* H red0art I redG "lue0art I "

    green0art I greenG pu"lic static 'olor (ed I new 'olor)>!FF, >, >*G pu"lic static 'olor &lue I new 'olor)>, >!FF, >*Gpu"lic static 'olor reen I new 'olor)>, >, >!FF*G pu"lic static 'olor $hite I new 'olor)>!FF, >!>!FF*G n the abo'e exampe# the +oor cass has the !ieds, redPart# buePart# greenPart# -ed# ue# /reen# and 0hite.

    %. With a&&ro&riate e#am&es e#&ain &arameter &assing in ".Ans: n ', parameter can "e passed either '( ,a$e or '( reference. 0assing parameterseference allows function mem"ers )methods, properties, inde!ers, operators and constructors*

    change the value of the parameters and have that change persist. To pass a parameter "y referenuse the ref or out keyword.e.g.: n the following e!ample, it is not the value of mynt that is passedG rather, a reference to my

    s passed. The parameter ! is not an intG it is a reference to an int. therefore, when ! is sDuared inshe method, what actually gets sDuared is what ! refers to: mynt. 4sing -ystemG c0arameter0assingal&y(ef H static void -Duaret)ref int !* H ! 6I!G'onsole.$riteLine);The value inside the method: H>< ,mynt*G -Duaret)ref mynt*G'onsole.$riteline);The value after calling the method: H>*

    12

  • 8/13/2019 61(Finish)

    13/23

    H temp I temp.Ne!tG inde! X XG return tempG pu"lic o"ect thisMint indH get Hf )Yalidnde!)inde!** throw new E!ception);nde! out of range.

  • 8/13/2019 61(Finish)

    14/23

    operator\ keyword. /perator overloading allows user%defined types such as structures and classesuse overloaded operators for easy manipulation of their o"ects. /perator overloading can "e achie"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!)innt img* Hthis.r I rG this.img I imgG pu"lic static 'omple!+dd operator )'omple!+dd c1, 'omple!+

    c=* Heturn new 'omple!+dd)c1.r c=.r, c1.img c=.img*G pu"lic override string To-tring)* Hreturn)-tring.Format)JH> H1iJ, r, img**G pu"lic static void 3ain)* H 'omple!+dd var

    new 'omple!+dd)@,?*G

    'omple! var= I new 'omple!)B,=*G 'omple!+dd total I var1 var=G 'onsole.$riteLine)JFcomple! num"er: H>J,var1*G'onsole.$riteLine)J-econd comple! num"er: H>J,var=*G 'onsole.$riteLine)JThe sum of the

    num"ers: H>J,total*G n this program uses operator overloading to create a comple! num"er class 'omple!+dd that deficomple! addition. The program displays imaginary and the real parts of the num"ers and the additesult using an override of the To-tring method.

    Lesson: B1. What is a &re&rocessor? What does the if6 ese6 eif6 endif6 define6 $ndwarning6 error6 and 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 processed as if there was a preprocessor. These directives are used during conditional compilat4nlike ' and ' directives, we cannot use these directives to create macros. + preprocessor direcmust "e the only instruction on a line.if:%if, "egins a conditional directive for testing a sym"ol, to see if they evaluate to true. f theyevaluate to true, the compiler evaluates all the code "etween the if and the ne!t correspond

    directive. The following operators can also "e used to evaluate multiple sym"ols, like: II )eDuasym"ol*,YI )ineDuality sym"ol*, ]] )and sym"ol*, ^^ )or sym"ol*e.g.:%define E&4 define 'B using -ystemG pu"lic class 3y'lass H pustatic void 3ain)* H

    if )E&4 ]] Y'B* 'onsole.$riteLine)JE&4 is definedJ*G elif )YE&4 ]] 'B*'onsole.$riteLine)J'B is definedJ*G elif )E&4 ]] 'B* 'onsole.$riteLine)JE&

    and 'B are definedJ*Gelse 'onsole.$riteLine)JE&4 and 'B are not definedJ*G endif

    ese:%else, creates a compound conditional directive, such that, if none of the e!pressions in preceding if or elif directives did not evaluate to true, the compiler will evaluate all code "etwelse and the su"seDuent endif.e.g.: %%define E&4 define 'B using -ystemG pu"lic class 3y'lass H pu

    static void 3ain)* Hif )E&4 ]] Y'B* 'onsole.$riteLine)JE&4 is defined

  • 8/13/2019 61(Finish)

    15/23

  • 8/13/2019 61(Finish)

    16/23

    %. 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 tperform large and comple! computations. Threads are the "asic unit to which an operating systallocates processor time, and more than one thread can run inside that process. Ad,antageM$ti&e threads:% 6'an communicate over a network, to a $e" server and to a data"ase. 6 0erfooperations that take a large amount of time. 6 istinguish tasks of varying priority. For e!ample, a hpriority thread manages time%critical tasks, and a low%priority thread performs other tasks. 6 +llow user interface to remain responsive, while allocating time to "ackground tasks. 0isad,antageM$ti&e threads: % 63emory reDuirement for the conte!t information reDuired "y process

    +pplication omain o"ects, and threads. Therefore, the num"er of processes, +pplication omo"ects, and threads which can "e created is limited "y memory availa"ility. 6 _eeping track of a lanum"er of threads consumes significant processor time. f there are too many threads, then there not "e any significant advantage of threads. 6 'ontrolling e!ecution of an application with mhreads can "e a source of many "ugs and it is very comple!.

    *. Write a note in +i'rar(

  • 8/13/2019 61(Finish)

    17/23

    intint6 % &'(; ob)ecto % int6; try { intint7 % int$o;Console.-riteine5nboxing 89.3 catc06nali!CastExceptione${Console.-riteine{23 Error: 6ncorrect unboxing.4 e$;3 3

    . What are the different methods s$&&orted '( (stem.D'7ect cass? i,e an e#am&e each.+ns: Following are the different methods supported "y -ystem./"ect: %

    a/ The E$as Method: This is a common operation, especially for searching and sortingcollections, it tests two o"ects for eDuality. The EDuals method of the o"ect class providedefault implementation that compares two reference type o"ects for reference eDuality. following code snippet shows the use of the EDuals method:

    e.g.:pu"lic static void 3ain)* Hstring str1I ;3ark

  • 8/13/2019 61(Finish)

    18/23

    publicclass7agge!rrayTest { publicstaticoi!"ain$ { int

  • 8/13/2019 61(Finish)

    19/23

    e!plicitly designed for data manipulation. The 'onnection o"ect provides connectivity to a data souThe 'ommand o"ect ena"les access to data"ase commands to return data, modify data, run stoprocedures, and so on. The ata(eader provides a high%performance stream of data from the dsource. Finally, the ata+dapter provides the "ridge "etween the ata-et o"ect and the data souThe ata+dapter uses 'ommand o"ects to e!ecute -L commands at the data source to "oth load 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 dataseading 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-L /LE & provider, /racle /LE & provider, and 5et /LE & provider. The /LE & ataprovider classes are present in the -ystem.ata./le" namespace.

    '/ + er,er data &ro,ider: This type of data provider is used to work specifically with3icrosoft -L -erver. + -L -erver data provider is recommended for working with a 3icrosof-L -erver data source, "ecause a -L -erver data provider allows fast access to a data sourwithout going through an /LE & or /&' layer. The -L -erver data provider classes arepresent in the -ystem.ata.-Dl'lient namespace.

    The .NET data provider is designed to "e lightweight, creating a minimal layer "etween the data souand application code, increasing performance without sacrificing functionality. The four maincomponents of .NET data provider: %1* "onnection: Esta"lishes a connection to a specified data source. =* "ommand: E!ecute

    command against a data source.?* 0ata 9eader: (eads a forward%only, read%only stream of data from a data source. A* 0Ada&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 parthe disconnected environment. + dataset is a disconnected, cached set of records that are retrievedrom a data"ase.

    +/.NET supports scala"ility "y working with datasets. ata"ase operations are performed on thedataset 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 present in the ataset class in the -ystem.ata namespace. The key components of a ataset are : 1* 0ataTa'e"oection : ! t contains all the ta"les retrieved from the atasource.=* 0ata9eation"oection : ! 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"oection : ! t contains all the rows in a datata"le.@* 0ata"o$mn"oection : ! t contains all the columns in a datata"le.

    *. Write a &rogram to show the demonstration of A0D.NET.Ans: usingSystem; usingSystem.Collections.Ieneric; usingSystem.Text;usingSystem.Jata.SKlClient; namespaceJemoFJ8FNET { classProgram {taticoi!"ainstringSKlConnectionconnectionString$; cn.8pen$;KlComman!cm! % ne>SKlComman!sSM4cn$; SKlJataGea!er!r % cm!.ExecuteGea!er$;>0ile!r.Gea!$${Console.-riteine!r

  • 8/13/2019 61(Finish)

    20/23

    6+ $e" service is ust "etween computer to compuapplications. 6 t is like a program on one compucalling a method that e!ists on another computer calling it through the nternet.6 + $e" service does have user interface. + $e" service is designedinteract with applications.6 $e" service or 23L wservice is ust a collection of methods that can "e cafrom some other computer, from a remote location. cloud in the middle of figure is the nternet. 6 The regoes "ack to the consumer. To the consumer ther

    very little difference from calling a method tharunning on the same machine, "ut it is running at soother 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 hauser 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 ust "etween compuo computer applications. t is like a program on one computer calling a method that e!ists on anot

    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" servnot some user "y clicking some "utton. /n the $e"%service side, the client can "e anything that seriali#e a reDuest and de%seriali#e the result that comes "ack. /n the $e"%service side, its work ype of the client.

    %. What is AP.NET?Ans: +-0.NET is an entirely new paradigm for server%side +-0 scripting. +-0.NET is a unified $development platform that provides the services necessary for us to "uild enterprise $e" applicatio+-0.NET is largely synta! compati"le with +ctive -erver 0agesG it also provides a new programmmodel and infrastructure that allow us to create secure, scala"le, sta"le and powerful applicatio+-0.NET is a compiled, .NET%"ased environmentG and allows us to take full advantage of the featurehe 'L(, such as type safety, inheritance, language interopera"ility and versioning. +-0.NET has "e

    designed to work with ;$hat Oou -ee s $hat Oou et< )$O-$O* KT3L editors and otprogramming tools, including 3icrosoft isual -tudio .NET.

    3. With a neat diagram e#&ain the e,ent handing &rocess of win formsOwe' forms.

    OPageanguage%C#utoEent-ireup%true Co!eHile%Jeault.aspx.cs6n0erits%FJeaultRJ8CTPE 0tml P5B6C 1//-(C//JTJ UT" &.2 Transitional//0ttp://>>>.>(.org/TG/x0tml&/JTJ/x0tml&1transitional.!t!Q0tmlQ0ea!Q/0ea!Qscript language%C# runat%sererQoi! SubmitBtnFClicL8b)ect sen!Eentrgse${"essage.Text % Ui D Uttp5tility.UtmlEnco!eName.Text$ D 4 T0anLsRRRRR ou 0electe!: D Category.Selecte!6tem;3/scriptQbo!yQcenterQorm action%Jeault.as

    met0o!%postrunat%sererQ0(QName: asp:textboxi!%Namerunat%serer/Q

    2)

  • 8/13/2019 61(Finish)

    21/23

    Category: asp:!rop!o>nlisti!%Categoryrunat%sererQasp:listitemQT8S/asp:listitemQasp:listitemQSP8GTS 96T/asp:listitemQasp:listitemQH8-EGS/asp:listitemQ/asp:!rop!o>nlist/0(Qasp:buttontext%ooLup8nClicL%SubmitBtnFClicLrunat%serer/Qasp:labeli!%"essagerunat%serer/Q/ormQ/centerQ/bo!yQ/0tmlQ

    Each +-0.NET server control is capa"le of e!posing an o"ect model containing properties, methand events. +-0.NET developers can use such o"ect model to cleanly modify and interact with page.6 The a"ove mentioned e!ample demonstrates how an +-0.NET page developer can handle /n'lick event from the Uasp:"utton runatIJserverJW control to manipulate the te!t property of Uasp:la"elrunatIJserverJ7W control.6 n this e!ample, when this we" form loads on the we" "rowhere is two La"el, one Te!t"o!, one ropownList, one &utton.6 $hen the 4-E( select any it

    present in the ropownList and click on the &utton, it displays a message along with the name

    he selected item from the dropdownlist.This event occurs due to +-0.NET server controls which handle it.

    *. What is the $se of AP.NET?Ans:+-0.NET is precompiled code so it "ecomes very easy to use it in we" applications developme$e can easily use the "enefits of these technologies, which include managed 'L( environment, tsafety, nheritance, language interopera"ility and versioning. +-0.NET provides a new programmmodel and infrastructure for more secure, scala"le, and sta"le applications. $e can write applicatin any .NET compati"le language, including &.NET, ', and 5-cript .NET. evelopers can easily use "enefits of these technologies, which include the managed 'L( environment, type safety, inheritanand so on.

    ). Write a &rogram to dis&a( LWecome to AP.NET times in increasing order of theiront siKe $sing AP.NET.

    Ans: OPageanguage%C#utoEent-ireup%true Co!eHile%Jeault.aspx.csn0erits%FJeaultOQ RJ8CTPE0tmlP5B6C1//-(C//JTJ UT" &.2 Transitional//EN0ttp://>>>.>(.org/TG/x0tml&/JTJ/x0tml&1transitional.!t!Q0tmlxmlns%0ttp://>>>.>(.org/&@@@/x0tmlQ 0ea!runat%sererQtitleQ5ntitle! Page/titleQ/0ea!Qbo!yQcenterQormi!%orm&runat%sererQ!iQOorinti%2; iA;iDD${OQ ontsiWe%O%iOQQ-elcome to t0e SP .NET/ontQbr/Q O3OQ

    /!iQ /ormQ /centerQ/bo!yQ/0tmlQ

    . What is the roe of (stem.We'?Ans: The -ystem.$e" namespace supplies classes and interfaces that ena"le "rowser and sercommunication. This namespace includes the Kttp(eDuest class that provides e!tensive informa

    a"out the current KTT0 reDuest, the Kttp(esponse class that manages KTT0 output to the client, he Kttp-erver4tility class that provides access to server%side utilities and processes. -ystem.$e" ancludes classes for cookie manipulation, file transfer, e!ception information, and output cache contr

    . Write a &rogram to demonstrate handing of ser,er contro e,ents.Ans: OPageanguage%C#utoEent-ireup%true Co!eHile%Jeault.aspx.csn0erits%FJeaultOQRJ8CTPE0tmlP5B6C1//-(C//JTJ UT" &.2 Transitional//EN0ttp://>>>.>(.org/TG/x0tml&/JTJ/x0tml&1transitional.!t!Q0tmlQ0ea!Q/0ea!Qscriptlanguage%C#runat%sererQoi!SubmitBtnFClicL8b)ectsen!er4 Eentrgse${"essage.Text % Ui D Uttp5tility.UtmlEnco!eName.Text$ D 4 T0anLsRRRRR ou 0ae Selecte!: D Category.Selecte!6tem; 3/scriptQbo!yQcenterQormaction%Jeault.aspxmet0o!%postrunat%sererQ 0(QName: asp:textboxi!%Namerunat%serer/Q Category: asp:!rop!o>nli!%Categoryrunat%sererQasp:listitemQT8S/asp:listitemQ asp:listitemQSP8GTS

    96T/asp:listitemQasp:listitemQH8-EGS/asp:listitemQ/asp:!rop!o>nlistQ/0(Qasp:buttontext%ooLup8nClicL%SubmitBtnFClicLrunat%serer/Q asp:labeli!%"essagerunat%serer/Q/ormQ/centerQ/bo!yQ/0tmlQ

    Lesson [:1. What is .NET 9emoting?Ans:(emoting is the process of communication "etween different processes, regardless of whetherhey are on the same or different computers. The .NET remoting system is an architecture designed

    simplify communication "etween o"ects e!isting in different application domains whether or not on same computer. t also simplifies communication "etween different conte!ts whether or not in thesame application domain. t can also use 23L encoding when interopera"ility with other remoting

    21

  • 8/13/2019 61(Finish)

    22/23

    systems is essential. (emoting was designed with security in mind, so we can seriali#e streams 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 "e used across protocol.

    $e" services work in a stateless environment where each reDuest results in a new o"created to service the reDuest. .NET (emoting supports state management options and identify multiple calls from the same client.

    $e" services seriali#e o"ects through 23L contained in the -/+0 messages and can thus ohandle items that can "e fully e!pressed in 23L. .NET (emoting relies on the life of the metadwithin assem"lies that contain information a"out data types. This limited metadata informatis passed a"out an o"ect, when it is passed "y reference.

    $e" services support interopera"ility across platforms and are good for heterogeneenvironments. .NET (emoting reDuires the clients to "e "y "uilt using .NET, which meanhomogeneous environment.

    The difference 'etween .NET 9emoting and 0"DM is isted as foows:

    '/3 relies on a proprietary "inary protocol that not all o"ect models support. t also wantscommunicate over a range of ports that are typically "locked "y firewalls. Kowever, .N(emoting supports different transport protocol formats and communication protocols. This allo.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 transportatiomedium that ena"les communication "etween the client and the server. These com&onents aree#&ained 'eow.

    The remote component is the o"ect that provides services to the client.

    The server creates and register a channel, which is a transportation medium, to listen at aspecified port. The server also registers the remote o"ect.

    + channel is a transportation medium through which communication "etween a server and aclient takes place.

    The client reDuests for the services of a remote o"ect. + client can choose the registered

    channels on the server to communicate with the remote o"ect. 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 arerepresented 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 functionahat is stored on another

    computer. The a"ove state shows the general remoting proce$hen "oth the server and client are configured properly, a clcreates a new instance of the server class. The remoting systcreates a pro!y o"ect that represents the class and returns to

    client o"ect a reference to the pro!y. $hen a client calls a meththe remoting system checks the type information, and sends the over the channel to the server process. + listening channel picksthe reDuest and forwards it to the server remoting system, whlocates and calls the reDuested o"ect. The process is then revers

    as the server remoting system "undles the response into a message and the server channel sendshe client channel. Finally, the client remoting system returns the result of the call to the client o"hrough the pro!y.

    *. E#&ain the ste&s or &hases in,o,ed in im&ementing .NET remoting a&&ications.

    22

  • 8/13/2019 61(Finish)

    23/23

    Ans:The phases involved in implementing .NET remoting applications are: 1* 'reate a remota"leo"ect: + remota"le o"ect is an o"ect that inherits from 3arshal&y(ef/"ect. 2/'reate a server toe!pose the remote o"ect: + server o"ect acts as a listener to accept remote o"ect reDuests. 3/'reate a client to use the remote o"ect: + client o"ect will connect to the server, create an instancehe o"ect using the server, and then e!ecute the remote methods.

    ). Write a &rogram to dis&a( L8eo Word string to demonstrate .NET remoting.Ans: usingSystem; usingSystem.Guntime.Gemoting; usingSystem.Guntime.Gemoting.C0annels;usingSystem.Guntime.Gemoting.C0annels.Tcp; namespaceGemoting {publicclassSample8b)ect: "ars0alByGe8b)ect { publicSample8b)ect$ {3publicstringUello-orl!$ { returnUello -orl!R; 3 3 3