[go: up one dir, main page]

0% found this document useful (0 votes)
17 views31 pages

Sunbeam MS - NET Notes

The .NET Framework is a comprehensive development platform for building applications across various Microsoft environments, including web and desktop applications. It features a common language runtime (CLR) for executing code and a class library that provides reusable code and services such as memory management and security. The framework supports multiple programming languages, enabling interoperability and simplifying application development through its extensive libraries and tools.

Uploaded by

gayandedo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
17 views31 pages

Sunbeam MS - NET Notes

The .NET Framework is a comprehensive development platform for building applications across various Microsoft environments, including web and desktop applications. It features a common language runtime (CLR) for executing code and a class library that provides reusable code and services such as memory management and security. The framework supports multiple programming languages, enabling interoperability and simplifying application development through its extensive libraries and tools.

Uploaded by

gayandedo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 31
SUNBEAM SUNBEAM Institute of Information Technology Student Name S What is the NET Framework? .NET APIs for Store/UWP apps Task-Based ys. Async Model "ur Task Parallel yx. library #0 Parallel LINQ se = : - E 7 BE oe SUNBEAM z Institute of Information Technology Placement Iniaive ‘The .NET Framework is a development platform for building apps for web, Windows, Windows Phone, jows Server, and Microsoft Azure. It consists of the common language runtime (CLR) and the .NET Framework class library, which includes a broad range of functionality and support for many industry standards. The .NET Framework provides many services, including memory management, type and memory safely, security, networking, and application deployment. It provides easy-to-use data structures and APls that abstract the lower-level Windows operating system. You can use different programming languages with the .NET Framework, including C#, Fi, and Visual Basic. The .NET Framework is a managed execution 2 environment for Windows that provides a variety of Winforms ASP.NET ADO.NET Services to its running apps. It consists of two major = components: the common language runtime (CLR), Cs Cs Fitch isthe execution engine that handles runring 3 apps, and the NET Framework Class Library, which Framework Class Library 2 provides a library of tested, reusable code that S = ee eerens a developers can call from their own apps. nv & The services that the NET Framework provides to running apps include the following: ‘© Memory management. In many programming languages, programmers are responsible for allocating and releasing memory and for handling object lifetimes. In .NET Framework apps, the CLR provides these services on behalf of the app. + A common type system. In traditional programming languages, basic types are defined by the compiler, which complicates cross-language interoperability. In the NET Framework, basic types are defined by the .NET Framework type system and are common to all languages that target the .NET Framework. + An extensive class library. Instead of having to write vast amounts of code to handle common low- level programming operations, programmers use a readily accessible library of types and their members from the NET Framework Class Library. * Development frameworks and technologies. The NET Framework includes libraries for specific areas of app development, such as ASP.NET for web apps, ADO.NET for data access, Windows Communication Foundation for service-oriented apps, and Windows Presentation Foundation for Windows desktop apps. * Language interoperability. Language compilers that target the NET Framework emit an intermediate code named Common Intermediate Language (CIL), which, in tum, is compiled at runtime by the common language runtime. With this feature, routines written in one language are accessible to other languages, and programmers focus on creating apps in their preferred languages. * Version compatibility. With rare exceptions, apps that are developed by using a particular version of the NET Framework run without modification on a later version * Side-by-side execution. The .NET Framework helps resolve version conflicts by allowing multiple versions of the common language runtime to exist on the same computer. This means that multiple versions of apps can coexist and that an app can run on the version of the .NET Framework with which SunBeam Institute of Information Technology, Pune, Karad Page 1 me execution applies to the .NE! Framework version groups 1.0777 al ide ©) 4.8. te class librarie i4.6.xi4.7.x14 8. Standard, developers creat ries that work ing. By targeting ers “by that version ofthe standard. For example, libraries, tha get ang ing. BY ms SUPPO! NET Framework 4, | Blair pe used by aps hal target the Work 4.6.1, NET Core git cL) o Infrastructure ( m Gommon Langue structure (CL) prove ‘Common Lang} jementing the core aspecl les a language-neutral platform for application deve lor NET Framework within the scope of CLI, these 4m and functions iy execution. By imp! .NET J# as Veode code col Compiler Compiler Compiler seus! -- Common Language Infrastructure ---- .NET compatible languages compile to a second platform-neutral language called ‘Comman Intermediate Language (CIL). Common The platform-specific Common Language Language Runtime (CLR) compiles CIL to machine- Runtime readable code that can be executed on the | current platform, 910011001010 11010101 100016 Fre 1e Comr Saat ad oes many seme Language Runtime (CLR). It serves as the execution engine of NET CLR Sully and tread manager eS memory management, type safely, exception handling, garbage Psi ae agement. All Programs written for NET Framework are executed by the opposed to being (NET Framework ar di - fe com . moe (ye rey Coed ro machen eo Common Intermediate Language code (Cl), a8 ites L code luring execution, an architecture-specific just-in-time ® SUNBEAM VE Institute of Information Technology Nin TEA Pacman tity INET Framowork Classes == 7 5 (futton vox | [UstConirat | [biecovery | es | | Grins ae Conti (Secu [Bessionsiate—] Corietons [70 } Funtin, Configuration) [We ServiceProcess | |nteronSeviees_) Diagnostics] [Retieeion |] [Text [Remoting ——) Globalization] [Resources | [Threading |(Seriatzation she NET Framework Class Librany (FCL) is organized in a hierarchy of namespaces. Most of the bul 0 pptcaton programming interfaces (APIS) are part of ether System." or Microsoft.* namespaces. These class apocaiplement many common functions, such 2s fle reading and wring, graphic rendering, database Iota and XML document manipulation, The class libraries are avaiable for al CL compliant languages. tte timplements the CLI Base Ciass Library (BCL) and olher class libreries—some are specified by CLI and other are Microsoft specific. are Gholudes a small subset ofthe entire class library and isthe core sel of cases that ao remtne basic API of CLR.NET Framework most classes considered bolng. part of BCL reside in seve ab.dl, Systema and System.Core.ll. BCL ciasses are availabe 9 MET Framework as well as its arsconive implementations including NET Compact Framework, Microsoft Siveright, .NET Core and Mono. a raters to ihe entire class library that ships with .NET Framework. ILincludes an expanded set of libraries, ety BCL, Windows Forms, ASP.NET, and Windows Presentation Foundation (WPF) bit also extensions {othe base clas libraries ADO.NET, Language Integrated Query (LING), Windows ‘Communication Foundation {WCE}, and Worklow Foundation (WF). FCL is much larger in scope than standard libraries for languages like cH Assemblies ‘Source code written in Cif is compiled into an intermediate language ‘Fhe code, along with resources such as bitmaps and strings, is stored on disk in an executal assembly(.exel.dl) ‘An assembly contains a manifest that provides security requirements. MyAssembly.dil Assembly Functions it contains IL code that CLR executes. It contains Manifest that makes PE files ESRC executables.An assembly is the unit at which permissions are requested and ‘ranted Every type's identity includes the name of the assembly in which it resides. metadata The assembly's manifest contains assembly metadata that is used for resolving types and satisfying resource requests. The assembly isthe smallest versionable unit Type metadata MSIL code in the common language runtime; all types and resources in the same assembly are Parts of Assembly (IL) that conforms to the CLI specification. ble file called an 5 information on the assembly's types, version, culture, and versioned as a unit. itforms a deployment unit. When an application starts, only the assemblies that the application intially calls must be present. Other assemblies, such as localization resources or assemblies containing utlity classes, can be retrieved on demand. This allows applications to be kept simple and thin when first downloaded. it ig the unit at which side-by-side execution is supported thus Assemblies are a fundamental part of programming with the NET Framework SunBeam Institute of Information Technology, Pune, Karad Page3 Bam). Assemby can De Single file ass 7 ‘ost and managed as single unit by CLR, ently or ind to optimize downloading an appli’ ion wag venly when need scam pos and resource” map to the actual files oma asso fdopends. hierjents and the Y Sgembly's implementation details, ttelite assembl¥ ion, exception handling, and ferred to as "managed code,” in vs that targets a specific system, rhage collect sometimes ref machine languags ies can include -NET Framework types and resources, table (PE) files. i fites, which are run directly from memory ang ic assembll to create dynamic such as System-Reflection.E! ose ok before EXECU i arora Ss igo common Taravede runtime APIS: assemblies: ; ng Aran 4, tne assembly is loaded into the CLR, which mig) Fon the information in the manifest. : : based Pipe secury requirements T°. Sl the CLR performs just inti Then to native machine instructions Those can be passed 10 OS: Global Assembly Cache frig recommended that only ‘assembly cache, When an assem Al fies that make up assembly. The cache performs these integri registered with GAC is shared asser reaistehes deployed in the global assembly cache mu nt take various actions, Executior When the G# ime (JIT) compilation to conver the IL wed to delete files from the global rivileges be allo checks are performed on isers with Administrator P' {assembly cache, integrity ply is added to the global y checks to ensure that assembly hae not be Y ily while assembly placed in applicat n folde ist have a strong name. en tampered with. Assembly is local or private assembly. Strong named assembly A stron. hs rena nafgme consists of the assembly's identity — Its simple text name, version number, and culture information — plus a public key and a digit tal signature. Itis generated from an assembly fil ‘ r ing pri tary on ae 48 fis ta ‘the corresponding private key.Strong names guarantee name sn you reference a strong-t 5 Wan ot sie mng-named assembly, you expect to get certain benefits, such a! .s versioning and t on the same Sideby ite Execution computer meena thet you abit 2 store and execute multiple versions of an componen! Sees amr httin Rei ee Stes a at bins to Suppo ares oe Pa ote con ‘over what versions of ‘a component and runtime an application uit into the infrastructure of the peas eect of different versions is possible due to strong naming Page 4 SunBeam Institute of Information Technology, Pune, Kai nf on: ey. , Pune, Karad ae 6 sunBeam = Institute of Information Technology Placement initatve Execution of Cif program Visual C# Pte CH Source | [_Resources eG) References C# 2.0 Complier Creates + Sa | an hewbaoes IL metadata & references loaded by CLR LNET Framework} Common Language Runtime Security / Garbage Collection / JIT Compiler Uses -NET Framework |__| “Class Libraries Converted to native machine code ‘Operating System Application domains Application domains provide an isolation boundary for security, reliability, and versioning, and for unloading assemblies. Application domains are typically created by runtime hosts, which are responsible for bootstrapping the common language runtime before an application is run Language Interoperability Language Interoperability simply means a function in VB .NET can be called by C# and vice-versa. When NET code is compiled, it results in MSIL, regardless of what language was used to write it, be it C#, VB.NET, Fit, etc. The resulting MSIL code can be used by a different language than the one it was written in, Language interoperability is the ability of code to interact with code that is written using a different programming language. Language interoperability can help maximize code reuse and, therefore, improve the efficiency of the development process. Every code written in any NET language and compiled could be reused from other .NET language. The IL disassembler The IL Disassembler is a companion tool to the IL Assembler (llasm.exe). Iidasm.exe takes a portable ‘executable (PE) file that contains intermediate language (IL) code and creates a text file suitable as input to Nasm.exe. The text fle produced by ildasm.exe can be used as input to the IL Assembler (/lasm.exe). This is useful, for example, when compiling code in a programming language that does not support all the runtime metadata attributes. After compiling the code and running its output through lidasm.exe, the resulting IL text file can be hand-edited to add the missing attributes. You can then run this text file through the IL Assembler to produce afinal executable file. C# Language C# language was created by Anders Hejisberg at Microsoft and launched in 2000. Ci#is a simple, modern, flexible, object-oriented, safe, and open source programming language SunBeam Institute of Information Technology, Pune, Karad Page S = suNBEAM ! Institute of Information Technology CH while providing powerful features suem mpoxitios of pos nny ol fs mathods nnd direct memory acs 3 Gi syinx simp dotogatos, AnOnyMoN Ay ve vie ueh 8 ae Topo onumrations. dela. prod to C and C+* and more Hoxbie than in Java, ee fund yin Ts Gul procas eT ruc, ners, ane events sr ofc “ dofine any number streanth of CH ae 4, Object Oriente od 1, this allows you to create modular maintainable a virion tanga ot Gein oe er gest avantages of CH Oe" © iS Osage Collection 2. Automatic beaker oo) eystem to erase and remove all the garbage present on the nas 94 Ve system and the system do not Got hanged during execution. Greate a mess i? i Leak Sino Problem Memory memory backup. There would be no problem of the mem, } # has a majo aceog get happens in the case of C++ language. In this case cay 22k ang PC and ey ‘Able SIEM. Ch dose, Sher such type of problems in : Gear edge on al ter languages. wh | 'to-Development | Seay Sass libraries make many functions easy to be implemented. C# has influence on most of th e Te pers ofthe work and it has a story in the programming world. . Cross Platform Sere spliction wil run wel ony ifthe machine has installed the NET framework. This is the most im, tirement for the Ci. also this could be an important opportunity for the young programmers to getty rem, trained with NET framework, 6. Better Integration i & Bcettone wrtten in NET wil have better integration and interperatability wih other NET Technologies ety Ca runs on CLR, making it easy to integrate with components written in other languages CLR-compatible languages) IDES (Specialy, 7. More Legible Coding swertzed poncept of get-set methods, so the codes becomes more legible. Also in CH, you don't need 0 ‘worry about header files. ‘Coding would be a worth to do in Ci. 8 Scarcity of Choice When you are in Microsoft stack, you have a tool for everything. So, basically you match Hen teers way i ovommend GH is very supporive kind of language specially forthe beginners. 9. Programming Support You can buy support from the Microsoft in C# (.NET framework) unlike Java where com munity is your support. So if things get wrong then you can solve your issues with the st r 10. Backward Compatibi ee INET applications work on windows platforms on! ji i ly and Microsoft keeps retiring support for old windows platforms. So always there would if Blairs. So ava there woud be a need to upgrade your NET femework if you are going one Data Types In C# ‘+ Citisa strongly typed language + Classified as Builtin type and User-defined type Or Classiti ‘sified as Value type — stores values and Reference type — stores references to data. {bool | Numerical |luser d [integral | Floating Institute of Information Technology Placement Initiative ce) SUNBEAM Value Types Structs | Enumerations jefined ® derived from a System.ValueType ~sbyte float(7) [ byte(s)_| double(15) | ® Stores Value directly |_char(i6) | a ® When assigned value is copied short(16)_| |Decimal t reference ushort(16)| | (128bit) eal id int(32, L ® Cannot used as base class uint(32) ® Default value generally zero (32) [long(64)_| ® Nullable types allowed YI ulong(64) Reference Types Class | > Classes and Interfaces are user defined. Intefaee | > objectis cosmic super class > string is also built in type represents immutable obiectaa strings f > delegate represent object oriented function pointer > store references to actual data delegate — Boxing and Unboxing By Boxing Value types can be treated as objects. This allows the value type to be stored on the garbage collected heap as an Object Unboxing extracts the value type from the object. example, the integer variable | is boxed and assigned to object o. inti= 123; object obj = (object) i; // boxing The object o can then be unboxed and assigned to integer variable i: object obj = 123; i= (int) obj! unboxing Boxing SunBeam Institute of Information Technology, Pune, Karad Page 7 (2 SsUNBEAT ArT ay class gives methods for creating, manipulating, searching, and sorting arrays. The Array class is The Array not part of the System.Col the IList interface. The string type [ mscorlib.dlt] SunBeam Institute of Informati n Technology, ype «This value 's a copy ofthe vaio ap, (i boxed) assigned to the variable YPC Valug int 123 lbyect 0-1 a + inti= 123; 11 a value type UnbOxIND On the heap «object 0 =i; // boxing jer + int] = (int) 0; / unboxing f ; + explicit conversion from type object 2 tov (i boxed) * Checking the object instance o mate sug bP [int L__r 323 @® itute of Information Technology a Insti ‘on the heap object required) + The result of this statement ig object reference 0, on the stacy 9 an references a value of the type kit t is a boxed value of the given value + Copying the value from the insta value-type variable. + Attempting to unbox nl or reference to incompatible value type will result insn InvalidCastException 08 ino the pect O17 E i lection because itis based namespace, but its still considered as a col a fray cass is the base class for language implementations that support arrays, 2.3.4.5} int] a=new int{S]; (51 1.2.3.4,5}; 7 eekDays = now sing {*Sun, "Mon, Tus in] a=new int (1, 23.3,4){5.6)); in] numbers = (4, 5, 6, 1, 2, 3, -2,-1, 0}; foreach (int in numbers) { System.Console.WriteLine(); } Console. WriteLine(numbers.Length); int) numbers = (4,5, 6, 1, 2,3, -2,-1, 0}; foreach (int in numbers) ‘System.Console.WriteLine(!); Console. WriteLine(numbers.Length); + Ajagged array is an array whose elements are arrays. + The elements of a jagged array can be of different dimensions and sizes. * Alagged array is sometimes called an “array of arrays." Sequence of Unicode characters alias for reference type System.String MLS operators check for values even though its reference type #:1L + operators can be used To avoid escape seq; str=@'cilfile, e8 Pune, Karad Pas 3} SUNBEAM =? institute of Information Technology th ring object iso Systom.Toxt StringBuildor class stringf] split(charl] seperators) @ Tomodify the same opjects, classes and structs Stjects aro instances of a given data type. The data type provides a bluprint fr the objoct tats instantiated when application is executed. |. New_data types are defined using classes & structs asses and structs form the building blocks of CH applications, containing code and data. Cit pplication wil always contain of al least one class. 4 aeiract ean be considered a lightweight class, ideal for creating data types that st represent a type that might later be extended via inheritance. data, and does no! Gi classes support inheritance, meaning they can derive from a previously defined class. lore small amounts of Class + class may have se Methods, Fields, Properties, Operators, Indexers, Events & other user defined types + Access specifiers © private, protected, public internal, protected internal Class definitions can be splitted in files ‘Static classes are sealed classes with static methods Only single inheritance is allowed Mallple interface inheritance is alowed structure ‘Struts are value types; classes are reference types ‘When passing a struct fo a method, itis passed by value instead of as a reference. Unlike classes, structs can be instantiated without using a new operator. Structs can declare constructors, but they must take parameters. inherited from other stuct.A struct can implement interfaces. A struct cannot ‘Al structs are inherit from System. alueType that inherits System.Object itis an error to initialize an instance field in struct Inheritance & Polymorphism «is operator checks for hierarchy relation bool flag = der_obj is base; as operator is used for dynamic type casting derived newobj = obj as derived; abstract classes & members are classes. + sealed members cannot be overridden + sealed classes cannot be further inherited; they are final ‘+ public class derived : base { ..) ‘solely used for inheritance - to define features of derived, non-abstract Operator overloading «By operator overloading, we can extend the meaning ofthe operator. By this we can use operator with user defined classes. ‘The operators are implemented as static functions of the class. 88. Ih 1], (), shorthand, . 2, >, news, sizeof operators cannot be overloaded Relational operators like ==, != should be overloaded in pair. public static Complex operator +(Complex 1, Complex 2); Conversion operators are used to convert a cass object into any other type and vice versa, Conversions dectared as implicit occur automaticaly when required Conversions declared as explicit require a cast to be called. new Keyword SunBeam Institute of Information Technology, Pune, Karad Page 9 SUNBEAM A) Institute of Information Technology led momory. ‘ator is used to allocate eu: ao iP eloved as. 04%, i ides all tho functions in base class with the am com en acess my netlon wh same name base gs". Using one dual, which makos function as a now virgo, foclnro a function as now virtual, wi z al fun Wo can even doclare 9 ter idden in further dorived classes using override ke, von {igeton ey in rary Ie anot access any’ such function with same signature inthe derived cece a bac roth faforence wo cannot access = powopot ‘When function dorivod class rofort sealed Keyword eeunction declared a the derived class. Thus sealed 1d cannot be overriden in v led functio ed yt base clas tht conet be modified or extended inthe cers tien funciona Peoled override tells that function is overridden in this class but cannot be overridde Tho species sea new function inthe derived class with same name we should use new, 9°" furthe, ed peael 25 const, isa constant variable and cannot be modified a + Tre vapetid be gen at comple time, where itis declared in dass, value = 3.142; const double Pl = 3.142; d to 3.142. Now value of Plis finalize 2. neon atten ames Jared as readonly, is assigned in Y fein anyother evar Te readonly elds value may nt be known at fhe comple time Metag THOT The const fa 3 ord 2 tne Geclred as abstract within a class then we cannot create object ofthat class. Such class must be declared as abstract. Functions declared abstract in base class must be overrides even create object of the derived class, ; + Astract lasses are used fo implement some common functionality that can be shared by the objets, of the derived classes. : + Funeion declared 2s abstract over overdes function in base class but make it abstract class. the derived class. Otherwise we cannot derived Use of abstract classes + Absract clas references are used to refer to objects ofthe derived classes. Thus they work like genetic references and give specific implementation depending on type of object. Also they implement tre ‘common functionality used by the derived class objects. * General we cteale collection Ike array of base class references and now we can store any objects bY manifest, and Ibeatous type from this assembly and create an instance of it Use Module to discover infomation such as the assembly that contains the module andthe classes in the module, al global methods or other specific, rnonglobal methods defined on the module. + Use Constructorinfo to discover information such as the name, parameters, aoces modifiers and implementation details (abstract or vital) ofa constructor. Use the GetCons\usor ‘GetConstructor method of a Type to invoke a specific constructor, Use Propertyino to discover information such as the Tame datatype, declaring type, reflected type, and read-only or writable satus of a property, and to get rset property values. Use Parameterinfo to discover information such 2: 8 parameter’s name, data type, whether a parameter is an input or output parameter, and the position of the parameter in a method signature. + Use CustorAttributeData to discover it reflection-only context of an application without creating instances of them. tom attributes when you are working in the ine atributes information about cus ibuteData allows you to exami domain. Customattrt ‘hnology, Pune, Karad Page 13, ee SunBeam Institute of Information Tec! [ 2 SUNBEAM = @ Institute of Information Technology Attributes fu mod of associating decorative information wth ype, meth, ‘Altrbutes provide 0 pow ' properties, Or to your program, Motadata is information embedded in ol your Ati a mor dseriptons of nl, Program such ag compile inst dotinod(given in tramowork) and user defined attributes, classified as prodofi They are clas ibutos are used in Pinvoke, Serialization, Interoperability, ot. Prodefined attributes are Us Custom Attributes own custom atibutes by defining an attribute class, a clas that derives gi You can create your own cus identifying altribule definitions in metadata fast and was n Jute, which makes ident b Bond tor oye ‘attribute decides usage of the attribute, «Inherited = true / false ectly of Regular Expresso on is @ pattem that could be matched against an input text. The .Net framework Fon i cea erelar expression engine that allows such matching. A pattern consists of one oe fe ov racer eal, operators, or constructs, ae “here are various categories of characters, operators, and constructs that lets you to define reguar * expressions The Regex class is used for representing a regular expression oForevey new value type parameter specialized version is created at runtime i ng refernces as refereces of any type have ference types only version in created for storing re faa Touse any Collen wih foreach loop it should suppor iterator or IEnumerable interface. Enumerator can be returned by “yield” keyword. We can write more than one yield retum statement, Yield statement cannot be there in unsafe blocks or try-catch blocks, anonymous methods, method with ref & out params. Generics in C# + Generics are template classes or functions written by programmer. C# generic type substitutions are performed at runtime. Use generic types to maximize code reuse, type safety, and performance, + Collection classes declared in System.Collections.Generic Generic interfaces, classes, methods, events and delegates can be created. Collection classes and Interfaces * Collection classes are defined as part of the System.Collections or System.Collections.Generic namespace + Most collection classes derive from the interfaces ICollection, IComparer, lEnumerable, IList, WDictionary, and IDictionaryEnumerator. { Semeimportant classes are ArrayList, SortedList, Stack, Queue, HashTable, etc * [ng generic collection classes provides increased type-safely and in some cases can provide better Performance, especially when storing value types ArrayList Class * Itrepresents an ordered collectio i alemaivetoanaecy n of an object that can be indexed individually. It is basically an + However, uni . . an indy eng eeey you can add and remove items from a list at a specified position using ay resizes itself automaticall ee Sterching and song ee el ly. It also allows dynamic memory allocation, adding, Example SunBeam Insti ‘te of Information Technology, Pune, Karad — SUNBEAm VE Institute of Information Technology Mas new ArrayLst() ars Add(887); : Gonsole.WriteLine("Capacity: (0), al. Capacity) Console WriteLine("Count: (0), al.Count); foreach (int in artist) Console.Write(i + Stack caS8 sin: fst out cal Itrepresents a last, first out collection of object. Its used when you need a la items, When you edd an item in the list, it is called pushing th tame er. pushing the item and when you first-out aocess of remove it, itis called Hashtable class he Hashtable class represents a collection of key-and-value pairs that are organi Tate o the key. Ituses the key to access the elements inthe callecion, oo“°4 based on he hash cample Achtable hashtb = new Hashtable); hashtb.Add(‘abet","Krishna’); hashtb.Add(“abe2","Kaveri’); hashtb.Add(“abe3","Venna’); if (hashtb.ContainsValue("krishna")) Console. WriteLine("This name is already present in the list) else hashtb.Add("abo4”, *Nitin"); ICollection key = hashtb.Key foreach (string i in key) Console.WriteLine(i + ": + hashtb fl); Dictionary class +The Dictionary class is a generic collection class in the System Collection. Generics namespace. TKey denotes the type of Key and TValue is the type of TValue, Example IDictionary d = newDictionary(); d.Add(1,"SunbeamKarad"); é.Add(2,"SunbeamPuneMarketYard"); d.Add(3,"ThreePuneHinjawadi"); foreach (KeyValuePair iin Console. WriteLine("Key: {0}, Value: {1 ixey, Value); /laccessing Dictionary using foreach for (int i= 0: 1 is an unordered collection of the unique elements. It comes under System.Collections.Generic namespace. The HashSet class provides high-performance set operations, SunBeam Institute of Information Technology, Pune, Karad Page 15 18 suNnBeEsAm Technology institute of Information aiamanta that the abject can hold. Hashsep mia tho mumbor 0 Me upticato eremant’ Toparations, uch nsoteT™ Ob) 4 cannot ¢ ny mathrernation ‘94 aot addition (unions) sie nd not eubtrnction ere i" now Hashsot Is a goneric collection whereas ArrayList {different interfaces that provide different nct>, ICollection,IReadOnlyList, ‘except that Li plements eight erable, ICollectior is an ArrayList teT> class im le, IEnum' List class. UisteT> collection is th eric colle functionalities, those [inteT>. IList, ReadOnly e same in The Lis ‘are IEnumerabli Collection + emp = newtist customers = new List(){ "Amit", Address ="Pune"}, Mahesh", Address = "Mumbai"), "Nilesh", Address = "Manglore"}, SunBeam Institute of Inform: Page 18 n Technology, Pune, Karad Mo | SUNBEAM Ty Institute of Information Technology ho Placement Iniiative Address, cecansce the sample data we have Wo customer objects wih Ades stating with *M* } is Asw : ger looping through entire collection; we shall get wo re 0 objects But this i sample d a + rea nes eat ine da How to hol eda Shou we po aed and eles alec or sgl see? or a pe ast ing 0 Wor Aout, Ft ews be concerned abot-"Can we ke hs ny pg yes! + YE ase LING ocolleton by ring SQL ke queries onthe clin, ade td the es es se "VAR" he result let us use “VAR type ‘catlier chapter. sen are cha savy "VAR?" . sre ont know what we are going fo get! ove goes the code forthe same: seult=ffom in cwstomers vac gree Stats) seket pie cade above the SQL ike syntax used is similar to Hibernate Query Language (HL). Hibernate sone ofthe popular ORM fameveork syntax isnt str SurTECT * FROM CUSTOMERS WHERE ADDRESS fo we have such a weird syntax? ojein the LINQ query used above; “FROM, ‘WHERE’, and ‘SELECT are not keywords! Those are actualy methods! ‘ofone method becomes an input to another method. It is more of chain of methods. * ight forward like SQL SELECT statement. Had itbeen SQL one would have written query ike Mv! why d Answer output God pint sout this query isthe query does not execute atthe mentioned statement t means if one tris to execute only LINQ Statement above; result will actually have nothing! LINQ query executes only when result is going to get used forthe fis time. Its ealled differed execution ‘hen one actually tries to use ‘result’ variable e.g. may be iteration of the result; then the query executes. + ttmeans wt like given below; one may see the result with data immediately: However ifone changes the query ‘yr result = (from c in customers where e,Address.Starts With("M") select) ToListO; | Inabove statement; change is we have asked to convert the entire result of the query in to LIST format. It means we have asked for immediate result! Hence in this case query executes immediately. File 10 - Serialization: Files and Directories: ‘Some of the very commonly used classes are as follows: + File - provides static methods for creating, copying, deleting, moving, and opening files, and helps create a FileStream object. + Fileinfo - provides instance methods for creating, copying, deleting, moving, files, and helps create a FileStream object. ‘ods for creating, moving, and enumerating through directories and opening * Directory - provides static meth and subdirectories. + Directoryinfo - provides instance methods for creating, moving, and enumerating through directories and subdirectories. + Path - provides methods and properties for processing directory strings in a cross-platform manner, SunBeam Institute of Information Technology, Pune, Karad Page 18 [ 2 SUNBEAM = Institute of Information Technology nce of bytes. Stream in netis an abstracts is nothing bul a sequel a Streams: Seem Fe, an inp ulput device, an IPC, or a TOPIP S2ckel. The programme, class, I could bo or specie dolls of operating system. Basic operations that cqa'ret is thus isolate sook, performed on a stream are read, write and Se eee f converting the stale of an object into a form that can be persi Serialization Oereevent of seaization is deseralization, which converts a stream into o tanepevte, The coon prosevves type fae, whic fs Useful or preserving the stata of _ pelveen al fions of an application. : itferent invocations of between diffe ‘alization serializes only public properties and fields and does not Preserve type fy + XML seri you want fo provide or consume deta without restricting the appcation ince Thy is useful when y ject memory menagement and provides an automated serie 2S data. The CLR manages o| = Object Bytes Database Memory a \When an objec is serialized, the name of the class, the assembly, and all the data members ofthe class instance are written o storege. When the class is serialize, the serialization engine ensure that the core objects not serialized more than once, if object has references. The only requirement placed on objet graphs is that all objects, referenced by the serialized object, must also be marked as Serializable + When the serialized class is deserialzed, the class is recreated and the values of all the data members are automatically restored. ‘+ Serialization can be done as Binary or XML or SOAP serialization. + Ifyou dont want to store any member then it should be marked with NonSerialized attribute. You can aso use XMLSerializer object with StreamWriter object to write in file. + Steps for serialization + Mark the class with Serializable attribute. Create a formatter object - Binary or SOAP Create FileStream object to store data Serialize object into file using formatter Close the stream Types of serialization: ‘There are basically 3 types of serialization: Binary: Binary serialization uses bina it encoding to i slrage or socket based netverk cea, ceeding to produce compact serialization for uses such as XML: XML serial and return values of see il22s the public fields and properties of an object, or the parameters iethods, "= Aefinonianguage (XSD) docuntoce

You might also like