Download as doc or pdf
Download as doc or pdf
You are on page 1of 8
(B) What is the use of “OverRides” and “Overridable” keywords ? ‘Overridable is used in parent class to indicate that a method can be overridden. Overrides is used in the child class to indicate that you are overriding a method (A) Where are all .NET Collection classes located ? Ssstem,Collection namespace has all the collection clacses available in NET: (A) What is ArrayList ? Array is whose size can increase and decrease dynamically. Array list can hold item of different types As Array list can increase and decrease size dynamically you do not have to use the REDIM keyword. You can access any item in array using the INDEX value of the array position, (A) What’s a HashTable ? “Twist » What's diference between HashVable and ArrayList @ ‘You cin access array using INDEX value of array, but how many times you know the seal value of index. [lashtable provides way of accessing the index using « user identified KEY value, thus removing the INDEX problem, (A) What are queues and stacks ? Queue is for fisstein, first-out (FIFO) structuses. Stack is for lastein, fisse-out (LIFO) structures (B) What is ENUM ? Ics used co define constants. (A) What is nested Classes ? Nested classes arc classes within dasses. In sample below “ClsNested” class has a “ChildNested” class nested inside ic, Public Class CisNested Public Class Childlested Public Sub ShowMessage () MessageBox, Show ("Hi this is nested class”) End sub End Class End Class ‘This is che way we can instantiate the nested class and make the method call. Din pobjcnildNested As New ClsNested.childlested() pobiChildNested.ShowMessage() (B)What is Operator Overloading in .NET? It provides a way to define and use operators such as +,-, and / for user-defined classes or strucss, It allows us to define/redefine the way operators work with our classes and structs, This allows programmers to make their custom types look and feel like simple types such as int and string, VBNET til now does not support operator overloading, Operator overloading is done by using the “Operator” keyword, Notex Operator cterleading is supported in VB.NET 2005 (I) In below sample code if we create a object of class2 which constructor will fire first 2 Public Clase Clasct Sub New() fend Sub End Class Public Class class? Inherits Classt Sub New() End Sub End Class * Lleave this w the readers.anu (B)What is the NET Garbage collector docs almost all dean up activity for your objects. Bu unmanaged resources (ex: + Windows API created objects, File, Database connection objects, COM cbjects etc) is oursde the scope of NET framework we have to explicitly clean our resources, For these types of objects NET framework provides Object. Finalize method which can be overridden and clean up code for unmanaged resources can be pat in this (A)Why is it preferred to not use finalize for clean up? Problem with finalize is that garbage collecton has to make two rounds in order to remove objects which have finalize methods. Below figure will make things clear regarding the two rounds of garbage collection rounds performed for the objects having finalized methods. In this scenario there are three objects Object! , Object2 and Object3. Object? has the finalize method overridden and remaining objects do not have the finalize method overtidden. Now when garbage collector runs for the first time it searches for objects whose memory has to free. He can see three objects but only cleans the memory for Object! and Odject3. ‘Object2 it pushes to the finalization queue. Now garbage collector runs for the second time, He see's there are no objects to be released and then checks for the finalization queue and at this moment it clears object2 fram the memory. Soif you notice that object2 was released from memory in the second round and not first. ‘Thar’: why the best practice is nor to write clean up NorNET resouress in Finalize method rather use the DISPOSE. ety cl sat caring Teco weno Psingte obs wichane ‘alae nebods inFrkzaton ue Faeleion qe i ‘ Coa Fa / Sooners Se top, ro li cos tom oo Sehetntargoue apn I Figure = 6.8 Garbage collect In uctlons ()How can we suppress a finalize method? GCSuppressFivalize (B)What is the use of DISPOSE method? Dispose method belongs to IDisposable interface, We had seen in the previous section how bad it can he to override the finalize method for writing the cleaning of unmanaged resources, So if any object wants to release its unmanaged code best is to implement Iisposable and override the Dispose method of [Disposable interface. Now once your class has exposed che Dispose method it’s the responsibility of the client to call the Dispose method to do the cleanup. (A)How do | force the Dispose method to be called automatically, as clients can forget to call Dispose method? Note = adi this question Call the Dispose method in Finalize method and in Dispose method suppress the finalize method using GCSuppressFinalize. Below is the sample code of the pattern. This is the bese way we do clean our unallocated resources and yes not to forget we do not get the hit of running the Garbage collector twice. Notes It ill suppress the finalig method thus anciding the two trip. Public Class CleTesting Implements Disposable Pablic Overloads Sub Disgose()implements IDispasaine,Dispase " ari ytour chan up cede here GC SuppressFinalige(Me) End Sub Proteted Overrides Suc Finalize() Disposed) End Sub End Class ())In what instances you will declare a constructor to be private? When we create a private constructor, we can nor create object of the dass directly fom. aclient, So you will use private constructors when you donot want instances of the class to be created by any extemal client, Example UTILITY functions in project wil have 20 instance and he used with out creating instance, 26 creating instances of the class would be watte of memory. ()Can we have different access modifiers on getiset methods of a property ? No we can not have different modifiers same property. The access modifier on a property applies to both its ger and set accessors (If we write a goto or a return statement in try and catch block will the finally block execute 7 The code in then finally always run even if there are statements like goto or a return, statements. (A)What is Indexer ? An indexeris a member tha: enables an object to be indexed in the same way as an array. (A)Can we have static indexer in C# ? No. (A)Can two catch blocks be executed? No, once the proper catch section is executed the control goes firally to block. So there will not be any scenarios in which multiple catch blocks will be executed. (A) What is the difference between System.String and System.StringBuilder classes? System Scring is immutable; System StringBuilder can have mutable string where a variety of operations can be performed.

You might also like