C#.NET FAQ




What is C#?

C# (pronounced C-Sharp) is a new programming language introduced with the Microsoft .NET framework and is no doubt the language of choice in .NET environment. It was first created in the late 1990's as part of Microsoft’s whole .NET strategy. It is a whole new language free of backward compatibility curse and a whole bunch of new, exciting and promising features. It is an Object Oriented Programming language, which at its core, has similarities with Java, C++ and VB.



What are implementation inheritance and interface inheritance?

Implementation inheritance is achieved when a class is derived from another class in such a way that it inherits all its members. Interface inheritance is when a class inherits only the signatures of the functions from another class.



What are generics in C#.NET?

Generic types to maximize code reuse, type safety, and performance. They can be used to create collection classes. Generic collection classes in the System.Collections.Generic namespace should be used instead of classes such as ArrayList in the System.Collections namespace.


What is the use of GetCommandLineArgs() method in C#.NET?

With GetCommandLineArgs() method, the command line arguments can be accessed. The value returned is an array of strings.
 


What is the use of System.Environment class in C#.NET?

The System.Environment class can be used to retrieve information like command-line arguments, the exit code, environment variable settings, contents of the call stack, time since last system boot, the version of the common language runtime.



What is an Exception in .NET?

Exceptions are errors that occur during the runtime of a program. The advantage of using exceptions is that the program doesn’t terminate due to the occurrence of the exception. Whenever an exception is occurred the .NET runtime throws an object of specified type of Exception. The class ‘Exception’ is the base class of all the exceptions..
 


What are Custom Exceptions?

Custom Exceptions are user defined exceptions.



What is a Constructor?

It is the first method that are called on instantiation of a type. It provides way to set default values for data before the object is available for use. Performs other necessary functions before the object is available for use.



Can private virtual methods be overridden in C#.NET?

No, moreover, you cannot access private methods in inherited classes. They have to be protected in the base class to allow any sort of access.
 


Is is possible to force garbage collector to run?

Yes, we can force garbage collector to run using System.GC.Collect().
 


What is an Event?

When an action is performed, this action is noticed by the computer application based on which the output is displayed. These actions are called events. Examples of events are pressing of the keys on the keyboard, clicking of the mouse. Likewise, there are a number of events which capture your actions.
 


What is Delegate?

Delegates are kind of similar to the function pointers. But they are secure and type-safe. A delegate instance encapsulates a static or an instance method. Declaring a delegate defines a reference type which can be used to encapsulate a method having a specific signature.
 


How does object pooling and connection pooling differ?

In Object pooling, you can control the number of connections. In connection pooling, you can control the maximum number reached. When using connection pooling, if there is nothing in the pool, a connection is created since the creation is on the same thread. In object pooling, the pool decides the creation of an object depending on whether the maximum is reached which in case if it is, the next available object is returned. However, this could increase the time complexity if the object is heavy.
 


What is Language Integrated Query (LINQ)?

LINQ is a set of extensions to .NET Framework that encapsulate language integrated query, set and other transformation operations. It extends VB, C# with their language syntax for queries. It also provides class libraries which allow a developer to take advantages of these features.
 


Explain the purpose of CultureInfo class. What namespace contains it?

System.Globalization namespace contains CultureInfo class. This class provides information about a specific culture, i.e. datetime format, currency, language etc.
 


Which is the class from where everything is derived in .NET?

System.Object. Object class is the ultimate base class of all classes in the .NET Framework, it is the root of the type hierarchy. It is often used as a generic argument in class methods - all classes are treatable as Object classes.



What is the use of assert() method?

Assert method is in debug compilation. It takes a boolean condition as a parameter. It shows error dialog if the condition is false and if the condition is true, the program proceeds without interruption.
 


Difference between the System.Array.CopyTo() and System.Array.Clone()?

System.Array.CopyTo() performs a deep copy of the array. System.Array.Clone() performs a shallow copy of the array
 


What is the purpose of Dispose method?

Dispose method is used to destroy the objects from the memory.
 


What is the difference between shadow and override?

In general when you extend a class you shadow fields with the same name in the base class and override virtual methods with the same name and parameter list in the base class. Overriding makes the base class method invisible. Shadowing a field only hides the field from view. You can still explicitly touch the hidden shadowed field if you wish. You cannot touch an invisible overridden method.
 


What is the difference between const and readonly in C#.NET?

The read only can be modified by the class it is contained in. However, the const cannot be modified. It needs to be instantiated only at the compile time.
 


Is there regular expression (regex) support available to C# developers?

Yes. The .NET class libraries provide support for regular expressions. Look at the System.Text.RegularExpressions namespace.
 


What is Anchoring a control and Docking a control?

Anchoring: used to resize controls dynamically with the form.
Docking: to adhere to the edges of its container.
 


What is Form level validation and Field level Validation?

Form level validation occurs once the user is ready to submit the form. The application checks the complete form at once and validates all the fields in it and informs the user about it. Field level validation occurs only for a specific field. E.g.: As soon as the user looses focus from a name input box, the application validates the data in that particular field and informs the user about it. They are normally used for mandatory fields using javascript.
 


What is Code-Access security?

Code access security is a mechanism that helps limit the access to the code by protecting the resources. It defines permissions which tell about the rights to access various. It also imposes restrictions on code at run time.


 
What is the difference between DataGrid control in Windows Forms and Web Forms?

Windows Forms controls have more functionality than Web Forms. Also, DataGrid in Web Forms has to be bound to the form before it displays any data.
 


What is the difference between Finalize() and Dispose()?

Dispose() is called by as an indication for an object to release any unmanaged resources it has held.Finalize() is used for the same purpose as dispose however finalize doesn’t assure the garbage collection of an object.Dispose() operates determinalistically due to which it is generally preferred.
 


How does the XmlSerializer work? What ACL permissions does a process using it require?

The XmlSerializer constructor generates a pair of classes derived from XmlSerializationReader and XmlSerializationWriter by analysis of the classes using reflection. Temporary C# files are created and compiled into a temporary assembly and then loaded into a process.The XmlSerializer caches the temporary assemblies on a per-type basis as the code generated like this is expensive. This cached assembly is used after a class is created.Therefore the XmlSerialize requires full permissions on the temporary directory which is a user profile temp directory for windows applications.


 
What are circular references?how garbage collection deals with circular references?

A circular reference is a run-around wherein the 2 or more resources are interdependent on each other rendering the entire chain of references to be unusable.There are quite a few ways of handling the problem of detecting and collecting cyclic references.
1. A system may explicitly forbid reference cycles.
2. Systems at times ignore cycles when they have short lives and a small amount of cyclic garbage. In this case a methodology of avoiding cyclic data structures is applied at the expense of efficiency.



What is the difference between Interface-oriented, Object-oriented and Aspect-oriented programming?

Interface oriented approach compels to develop the software based on the contract. Object oriented approach emphasizes on its aspects like, Abstraction, Encapsulation, Inheritance, Polymorphism. Cross cutting concerns cannot be implemented in object oriented programming. That’s not the case with aspect-oriented. However, there is a risk of system failure in this situation.
 


What is the accessibility modifier "protected internal" in C#.?

The Protected Internal access modifier can be accessed by:
Members of the Assembly
The inheriting class
The class itself,
Its access is limited to the types derived from the defining class in the current assembly or the assembly itself.



What is the difference between Debug.Write and Trace.Write? When should each be used?

Debug.Write: Debug Mode, Release Mode (used while debuging a project).
Trace.write: Release Mode (used in Released verion of Applications).



What are Jagged Arrays in C#?

A special type of array is introduced in C#. A Jagged Array is an array of an array in which the length of each array index can differ. Example: A Jagged Array can be used is to create a table in which the lengths of the rows are not same. This Array is declared using square brackets ( [ ] ) to indicate each dimension.
 


How do you prevent the class from being inheritance??

Simply include the keyword ‘Sealed’ in front of the class keyword.



What’s the advantage of using System.Text.StringBuilder over System String?

String Builder is more efficient in cases where there is a large amount of string manipulation. Strings are immutable, so each time a string is changed, a new instance in memory is created.
 


Explain the use of abstraction in C#.NET?

Abstraction is used to create a common set of methods that might have different specific implementations by subclasses. Abstract class cannot be instantiated and consists of abstract methods without any implementations. Classes inheriting from abstract class must implement all the methods in abstract class.
 


What is the Difference between instance data and class data?

Class data in terms of static class is the data that particular class holds in its structure. Instances can refer to different objects of the same class that hold different values using the same class structure in memory heap.
 


Explain the significance of static method?

Static methods are used when we want only one copy of that method to perform action and remain active at a single point in time.
 


Explain the uses of boxing and unboxing?

Boxing and Unboxing are used to convert value types into reference types and vice versa. Developers often need to make some methods generic and hence create methods that accept objects rather than specific value types. The advantage of reference types is that they don’t create a copy of the object in memory, instead pass the reference of the data in the memory. This uses memory much more efficiently, especially, if the object to be passed is very heavy.
 


Explain the Debug class methods?

a. Assert:This method checks for a condition. It displays a user message if the condition is false.
b. Write:used to write information which will be used by Trace Listeners.
c. WriteIf:Write information for Trace Listeners only if the condition is true.
d. WriteLine: same as write but, every time writes in a new line.
e. WriteLineIf:same as WriteIf but everytime writes in a new line.
 


Is there an equivalent of exit() for quitting a C# .NET application?

Yes, you can use System.Environment.Exit(int exitCode) to exit the application or Application.Exit() if it’s a Windows Forms app. 
 


Is there a way to force garbage collection?

Yes. Set all references to null and then call System.GC.Collect(). If you need to have some objects destructed, and System.GC.Collect() doesn’t seem to be doing it for you, you can force finalizers to be run by setting all the references to the object to null and then calling System.GC.RunFinalizers().
 


Is it possible to restrict the scope of a field/method of a class to the classes in the same namespace?

There is no way to restrict to a namespace. Namespaces are never units of protection. But if you’re using assemblies, you can use the ‘internal’ access modifier to restrict access to only within the assembly



How do I implement function pointers in C#?

Delegates provide the functionality of function pointers in C#. A delegate is a type that references a method. Once a delegate is assigned a method, it behaves exactly like that method.
 


What is partial class?
partial classes mean that your class definition can be split into multiple physical files. Logically, partial classes do not make any difference to the compiler. During compile time, it simply groups all the various partial classes and treats them as a single entity.
 


What does the volatile modifier do?
The volatile modifier is usually used for a field that is accessed by multiple threads without using the lock statement to serialize access. Using the volatile modifier ensures that one thread retrieves the most up-to-date value written by another thread.
 


Why do I get a security exception when I try to run my application?

Some security exceptions are thrown if you are working on a network share. There are some parts of the frameworks that run if being run off a share (roaming profile, mapped drives, etc.). To see if this is what's happening, just move the executable over to your local drive and see if it runs without the exceptions. One of the common exceptions thrown under these conditions is System.Security.SecurityException.
 


What is the difference between directcast and ctype

DirectCast requires the run-time type of an object variable to be the same as the specified type.The run-time performance of DirectCast is better than that of CType, if the specified type and the run-time typeof the expression are the same. Ctype works fine if there is a valid conversion defined between the expression and the type.



How to create and manage files in c#?

Using System.IO namespace and FileStream and StreamWriter classes.
 


What is FormClosed and FormClosing events?
The FormClosing event occurs as the form is being closed.You can Cancel this event. If you cancel this event, the form remains opened. To cancel the closure of a form, set the Cancel property of the FormClosingEventArgs passed to your event handler to true. The FormClosed event occurs after the form has been closed by the user. When a form is closed, it is disposed, releasing all resources associated with the form



TekTipsDownload
GateExam
Academic Projects
TekTipsExperts



 
Site optimized for IE7, 1280 X 768 and above. Copyright © 2010 - 2018 KTS InfoTech
Site Developed Using KTS WebCloud