Join Our Email Alerts-Subscribe
Important Note:Login & Check Your Email Inbox and Activate Confirmation Link


Enter Your Email :

Copyright Disclaimer:
Section 107 of the Copyright Act Fair Use Contents .
We are forwarding content link(s) from our website to content website & We are not serving any contents.
Main Source:Google.com.All the Content PDF link(s) is/are obtained from GoogleSearch
for the purpose of Education & Teaching Intention. Not for commercial purpose.
Technicalsymposium.com is not liable/responsible for any copyright issues.


C# Materials Free Download



What are the Arrays in C#.Net? 

Answer: 

Arrays are powerful data structures for solving many programming problems. You saw during the creation of variables of many types that they have one thing in common, they hold information about a single item, for instance an integer, float and string type and so on. So what is the solution if you need to manipulate sets of items? One solution would be to create a variable for each item in the set but again this leads to a different problem. How many variables do you need? 

So in this situation Arrays provide mechanisms that solves problem posed by these questions. An array is a collection of related items, either value or reference type. In C# arrays are immutable such that the number of dimensions and size of the array are fixed. 

Arrays Overview 

An array contains zero or more items called elements. An array is an unordered sequence of elements. All the elements in an array are of the same type (unlike fields in a class that can be of different types). The elements of an array accessed using an integer index that always starts from zero. C# supports single-dimensional (vectors), multidimensional and jagged arrays. 

Elements are identified by indexes relative to the beginning of the arrays. An index is also commonly called indices or subscripts and are placed inside the indexing operator ([]). Access to array elements is by their index value that ranges from 0 to (length-1). 

Array Properties

• The length cannot be changed once created.

• Elements are initialized to default values.

• Arrays are reference types and are instances of System.Array.

• Their number of dimensions or ranks can be determined by the Rank property.

• An array length can be determined by the GetLength() method or Length property.

25. What is the Constructor Chaining in C#? 

Answer: constructor chaining is a way to connect two or more classes in a relationship as Inheritance, in Constructor Chaining every child class constructor is mapped to parent class Constructor implicitly by base keyword so when you create an instance of child class to it’ll call parent’s class Constructor without it inheritance is not possible. 

26. What’s the difference between the System.Array.CopyTo() and System.Array.Clone()? 

Answer: 

Clone: 

Method creates a shallow copy of an array. A shallow copy of an Array copies only the elements of the Array, whether they are reference types or value types, but it does not copy the objects that the references refer to. The references in the new Array point to the same objects that the references in the original Array point to. 

CopyTo: 

The Copy static method of the Array class copies a section of an array to another array. The CopyTo method copies all the elements of an array to another one-dimension array. The code listed in Listing 9 copies contents of an integer array to an array of object types. 

27. Can Multiple Catch Blocks executed in c#? 

Answer: 

we can use multiple Catches block with every try but when any Exceptions is throw by debugger so every catches match this exception type with their signature and catch the exception by any single catch block so that means we can use multiple catches blocks but only one can executed at once like: 

1. using System; 

2. class MyClient { 

3. public static void Main() { 

4. int x = 0; 

5. int div = 0; 

6. try { 

7. div = 100 / x; 

8. Console.WriteLine("Not executed line"); 

9. } catch (DivideByZeroException de) { 

10. Console.WriteLine("DivideByZeroException"); 

11. } catch (Exception ee) { 

12. Console.WriteLine("Exception"); 

13. } finally { 

14. Console.WriteLine("Finally Block"); 

15. } 

16. Console.WriteLine("Result is {0}", div); 

17. } 

18. } 

28. What is Singleton Design Patterns and How to implement in C#? 

Answer: 

What is Singleton Design Pattern?

1. Ensures a class has only one instance and provides a global point of access to it.

2. A singleton is a class that only allows a single instance of itself to be created, and usually gives simple access to that instance. 

3. Most commonly, singletons don't allow any parameters to be specified when creating the instance, since a second request of an instance with a different parameter could be problematic! (If the same instance should be accessed for all requests with the same parameter then the factory pattern is more appropriate.) 

4. There are various ways to implement the Singleton Pattern in C#. The following are the common characteristics of a Singleton Pattern. 

• A single constructor, that is private and parameterless.

• The class is sealed.

• A static variable that holds a reference to the single created instance, if any.

• A public static means of getting the reference to the single created instance, creating one if necessary.

What is multicast delegate in c#? 

Answer 

Delegate can invoke only one method reference has been encapsulated into the delegate.it is possible for certain delegate to hold and invoke multiple methods such delegate called multicast delegates.multicast delegates also know as combinable delegates, must satisfy the following conditions: 

• The return type of the delegate must be void. None of the parameters of the delegate type can be delegate type can be declared as output parameters using out keywords. 

• Multicast delegate instance that created by combining two delegates, the invocation list is formed by concatenating the invocation list of two operand of the addition operation. Delegates are invoked in the order they are added. 

Implement Multicast Delegates Example:

1. using System; 

2. using System.Collections.Generic; 

3. using System.Linq; 

4. using System.Text; 

5. delegate void MDelegate(); 

6. class DM { 

7. static public void Display() { 

8. Console.WriteLine("Meerut"); 

9. } 

10. static public void print() { 

11. Console.WriteLine("Roorkee"); 

12. } 

13. } 

14. class MTest { 

15. public static void Main() { 

16. MDelegate m1 = new MDelegate(DM.Display); 

17. MDelegate m2 = new MDelegate(DM.print); 

18. MDelegate m3 = m1 + m2; 

19. MDelegate m4 = m2 + m1; 

20. MDelegate m5 = m3 - m2; 

21. m3(); 

22. m4(); 

23. m5(); 

24. } 

25. } 

32. Difference between Equality Operator (==) and Equals() Method in C#. 

Answer: 

Both the == Operator and the Equals() method are used to compare two value type data items or reference type data items. The Equality Operator (==) is the comparison operator and the Equals() method compares the contents of a string. The == Operator compares the reference identity while the Equals() method compares only contents. Let’s see with some examples. 

In this example we assigned a string variable to another variable. A string is a reference type and in the following example, a string variable is assigned to another string variable so they are referring to the same identity in the heap and both have the same content so you get True output for both the == Operator and the Equals() method. 

1. using System; 

2. namespace ComparisionExample { 

3. class Program { 

4. static void Main(string[] args) { 

5. string name = "sandeep"; 

6. string myName = name; 

7. Console.WriteLine("== operator result is {0}", name == myName); 

8. Console.WriteLine("Equals method result is {0}", name.Equals(myName)); 

9. Console.ReadKey(); 

10. } 

11. } 

12. } 

33. Difference between is and as operator in C#. 

Answer: 

"is" operator 

In the C# language, we use the "is" operator to check the object type. If the two objects are of the same type, it returns true and false if not. 

Let's understand the preceding from a small program. 

We defined the following two classes:

1. class Speaker { 

2. public string Name { 

3. get; 

4. set; 

5. } 

6. } 

7. class Author { 

8. public string Name { 

9. get; 

10. set; 

11. } 

12. } Now, let's try to check the preceding types as:

1. var speaker = new Speaker { Name="Gaurav Kumar Arora"}; 

We declared an object of Speaker as in the following:

1. var isTrue = speaker is Speaker; 

In the preceding, we are just checking the matching type. Yes, our speaker is an object of Speaker type.

1. Console.WriteLine("speaker is of Speaker type:{0}", isTrue); 

So, the results as true.

But, here we get false:

1. var author = new Author { Name = "Gaurav Kumar Arora" }; 

2. var isTrue = speaker is Author; 

3. Console.WriteLine("speaker is of Author type:{0}", isTrue); 

Because our our speaker is not an object of Author type.

"as" operator:

The "as" operator behaves similar to the "is" operator. The only difference is it returns the object if both are compatible to that type else it returns null. 

Let's understand the preceding with a small snippet as in the following:

1. public static string GetAuthorName(dynamic obj) 

2. { 

3. Author authorObj = obj as Author; 

4. return (authorObj != null) ? authorObj.Name : string.Empty; 

5. } 

We have a method that accepts dynamic objects and returns the object name property if the object is of the Author type. 

Here, we declared two objects:

1. var speaker = new Speaker { Name="Gaurav Kumar Arora"}; 

2. var author = new Author { Name = "Gaurav Kumar Arora" }; 

The following returns the "Name" property:

1. var authorName = GetAuthorName(author); 

2. Console.WriteLine("Author name is:{0}", authorName); 

It returns an empty string:

1. authorName = GetAuthorName(speaker); 

2. Console.WriteLine("Author name is:{0}", authorName); 

34. How to use Nullable<> Types in .Net? 

Answer: 

A nullable Type is a data type is that contain the defined data type or the value of null. 

You should note here that here variable datatype has been given and then only it can be used. 

This nullable type concept is not comaptible with "var". 

I will explain this with syntax in next section. 

Declaration: 

Any DataType can be declared nullable type with the help of operator "?". 

Example of the syntax is as Follows :- 

1. int? i = null; 

As discussed in previous section "var" is not compatible with this Nullable Type. 

So we will have Compile Time error if we are declaring something like: -

1. var? i = null; 

though following syntax is completely fine :- 

1. var i = 4; 

35. Different Ways of Method can be overloaded.

Answer: 

Method overloading is a way to achieve compile time Polymorphism where we can use a method with the same name but different signature, Method overloading is done at compile time and we have multiple way to do that but in all way method name should be same. 

• Number of parameter can be different. 

• Types of parameter can be different. 

• Order of parameters can be different. 

What is an Object Pool in .Net? 

Answer: 

Object Pooling is something that tries to keep a pool of objects in memory to be re-used later and hence it will reduce the load of object creation to a great extent. This article will try to explain this in detail. The example is for an Employee object, but you can make it general by using Object base class. 

What does it mean? 

Object Pool is nothing but a container of objects that are ready for use. Whenever there is a request for a new object, the pool manager will take the request and it will be served by allocating an object from the pool. 

How it works? 

We are going to use Factory pattern for this purpose. We will have a factory method, which will take care about the creation of objects. Whenever there is a request for a new object, the factory method will look into the object pool (we use Queue object). If there is any object available within the allowed limit, it will return the object (value object), otherwise a new object will be created and give you back. 

37. What are generics in c#.net? 

Answer: 

Generics allow you to delay the specification of the data type of programming elements in a class or a method, until it is actually used in the program. In other words, generics allow you to write a class or method that can work with any data type. 

You write the specifications for the class or the method, with substitute parameters for data types. When the compiler encounters a constructor for the class or a function call for the method, it generates code to handle the specific data type. 

Generic classes and methods combine reusability, type safety and efficiency in a way that their non-generic counterparts cannot. Generics are most frequently used with collections and the methods that operate on them. Version 2.0 of the .NET Framework class library provides a new namespace, System.Collections.Generic, that contains several new generic-based collection classes. It is recommended that all applications that target the .NET Framework 2.0 and later use the new generic collection classes instead of the older non-generic counterparts such as ArrayList. 

Features of Generics 

Generics is a technique that enriches your programs in the following ways:

• It helps you to maximize code reuse, type safety and performance.

• You can create generic collection classes. The .NET Framework class library contains several new generic collection classes in the System.Collections.Generic namespace. You may use these generic collection classes instead of the collection classes in the System.Collections namespace. 

• You can create your own generic interfaces, classes, methods, events and delegates.

• You may create generic classes constrained to enable access to methods on specific data types.

• You may get information on the types used in a generic data type at run-time using reflection.

38. Describe the accessibility modifiers in c#.Net.

Answer: 

Access modifiers are keywords used to specify the declared accessibility of a member or a type. 

Why to use access modifiers? 

Access modifiers are an integral part of object-oriented programming. They support the concept of encapsulation, which promotes the idea of hiding functionality. Access modifiers allow you to define who does or doesn't have access to certain features. 

In C# there are 5 different types of Access Modifiers. 

39. What is Virtual Method in C#? 

Answer: 

A virtual method is a method that can be redefined in derived classes. A virtual method has an implementation in a base class as well as derived the class. It is used when a method's basic functionality is the same but sometimes more functionality is needed in the derived class. A virtual method is created in the base class that can be overridden in the derived class. We create a virtual method in the base class using the virtual keyword and that method is overridden in the derived class using the override keyword. 

When a method is declared as a virtual method in a base class then that method can be defined in a base class and it is optional for the derived class to override that method. The overriding method also provides more than one form for a method. Hence it is also an example for polymorphism. 

When a method is declared as a virtual method in a base class and that method has the same definition in a derived class then there is no need to override it in the derived class. But when a virtual method has a different definition in the base class and the derived class then there is a need to override it in the derived class. 

When a virtual method is invoked, the run-time type of the object is checked for an overriding member. The overriding member in the most derived class is called, which might be the original member, if no derived class has overridden the member. 

Virtual Method

1. By default, methods are non-virtual. We can't override a non-virtual method.

2. We can't use the virtual modifier with the static, abstract, private or override modifiers. 

40. What are the Difference between Array and ArrayList in C#.Net?

Answer: 

Difference between Array and ArrayList 

41. What you understand by Value types and Reference types in C#.Net? 

Answer: 

In C# data types can be of two types: Value Types and Reference Types. Value type variables contain their object (or data) directly. If we copy one value type variable to another then we are actually making a copy of the object for the second variable. Both of them will independently operate on their values, Value Type member will located into Stack and reference member will located in Heap always. 

Let consider each case briefly.

1. Pure Value Type 

Here I used a structure as a value type. It has an integer member. I created two instances of this structure. After wards I assigned second instance to the first one. Then I changed the state of second instance, but it hasn't effect the first one, as whole items are value type and assignments on those types will copy only values not references i.e. in a Value Type assignment, all instances have its own local copy of members. 

2. Pure Reference Type 

I created a class and added a "DataTable" as a Reference Type member for this class. Then I performed the assignments just like below. But the difference is that on changing the state of second instance, the state of first instance will automatically alter. So in a Reference Type assignment both Value and Reference will be assigned i.e. all instances will point to the single object. 

3. Value Type With Reference Type 

This case and the last case to come are more interesting. I used a structure in this particular scenario also. But this time it includes a Reference Type(A Custom Class Object) Member besides a Value Type (An Integer) Member. When you performing the assignments, it seems like a swallow copy, as Value Type member of first instance won't effected, but the Reference Type member will alter according to the second instance. So in this particular scenario, assignment of Reference Type member produced a reference to a single object and assignment of Value Type member produced a local copy of that member. 

4. Reference Type With Value Type 

Contrary to the above case, in this scenario, both Reference & Value Types will be effected. I.e. a Value Type member in a Reference Type will be shared among its instances. 

42. What is Serialization? 

Answer: 

Serialization means saving the state of your object to secondary memory, such as a file. 

Suppose you have a business layer where you have many classes to perform your business data. 

Now suppose you want to test whether your business classes give the correct data out without verifying the result from the UI or from a database. Because it will take some time to process. 

SO what you will you do my friend? 

Here comes Serialization. You will serialize all your necessary business classes and save them into a text or XML file. 

on your hard disk. So you can easily test your desired result by comparing your serialized saved data with. 

your desired output data. You can say it is a little bit of autonomic unit testing performed by the developer. 

There are three types of serialization:

1. Binary serialization (Save your object data into binary format).

2. Soap Serialization (Save your object data into binary format; mainly used in network related communication).

3. XmlSerialization (Save your object data into an XML file).

Source: Contents are provided by Technicalsymposium Google Group Members. 
Disclaimer: All the above contents are provided by technicalsymposium.com Google Group members. 
Further, this content is not intended to be used for commercial purpose. Technicalsymposium.com is not liable/responsible for any copyright issues.


Download Technical Interview Materials PDF-Free Download

Technical Interview Questions and Answers Notes PDF
Placement Materials PDF-Free Download



Technicalsymposium.com-All Study Materials PDF-Free Download







Technicalsymposium.com-Free Live Support-Chat with Our Experts

Official Contact: +91-9245556793 (Whatsapp Message / SMS / Voice Call)


Our Expert team is ready to answer all your questions immediately-Feel free to speak in Tamil/English.

(Example:Events info/Lecture Notes/Off-Campus & All Jobs/Projects & All education information)

Working hrs (IST): (Morning: 10:00AM-3:00 PM) and (Evening:5:00 PM to 10:00 PM)

All Latest Question & Answer Page (FAQ)-Click here