We are providing online training of realtime Live project on Asp.Net MVC with Angular and Web API. For more information click here. If you have any query then drop the messase in CONTACT FORM

Friday, March 20, 2015

Advanced questions and answers of c#



1. What is .NET Remoting?.

Net Remoting enables communication between applications across separate domains or networks. .Net objects are exposed to remote processes to have interprocess communication. With remoting, we can use TCP or HTTP communications protocols on any port. We can use text or binary formatting. .Net Remoting supports server activated (single call and singleton), as well as client, activated objects.

2. What are the 2 message encoding formats supported by .NET Remoting and when do you choose one over the other?

Message Encoding Formats:
1. Binary encoding.
2. XML encoding.
Applications can use binary encoding where performance is critical or XML encoding where interoperability with other remoting frameworks is essential.

3. What are the two types of .NET remote objects?

1. Client-activated objects - Client-activated objects are under the control of a lease-based lifetime manager that ensures that the object is garbage collected when its lease expires.
2. Server-activated objects - In the case of server-activated objects, developers have a choice of selecting either a "single call" or "singleton" model. The lifetime of singletons is also controlled by a lease-based lifetime.

4. What is considered as Remote Object?

Any object outside the application domain of the calling application is considered a remote object, even if the objects are executing on the same machine.

5. Can we treat every object as a remote object?

Objects that cannot be serialized cannot be passed to a different application domain and are therefore nonremotable.

6. What are the ways in which an object can be serialized?

1. Mark our class with a serializable attribute.
2. Make our class implement the ISerializable interface.

7. How can you change an object into a remote object?

Any object can be changed into a remote object by deriving it from MarshalByRefObject.

8. What happens when a client activates a remote object?

When a client activates a remote object, it receives a proxy to the remote object. All operations on this proxy are appropriately directed to enable the remoting infrastructure to intercept and forward the calls appropriately.

9. What are proxy objects and what is the use of these proxy objects?

Proxy objects are created when a client activates a remote object. The proxy object acts as a representative of the remote object and ensures that all calls made on the proxy are forwarded to the correct remote object instance.

10. Explain Marshalling and its types in .Net Remoting.

Objects can't be transmitted as such over a communication channel. The objects are packed into message buffer before transmitted. This process is called marshaling. There are two different ways to Marshal objects
Marshal by Value: The server creates a copy of the remoting object's state and passes it to the client. You need to implement your classes to have marshal by value features either by implementing the ISerializable interface or using the attribute. Here you need to copy the whole object to the client which means with a large size object, the communication overhead is significant.
Marshal by Reference: In this type, the proxy is created by the reference of the server objects. The class must extend the System.MarshalByRefObject to implement marshal by reference. Here, the client keeps server object reference which means a round trip to the server with each method call.

11. Explain Serialization Formatters in .NET Remoting?

In .Net Remoting, the objects are shared over a distributed network. The objects are transmitted in serialized form. The objects are first serialized into message data before it is sent with the wire. On the other end of the wire, this serialized data is read and desterilized back to the actual object. This process of converting objects into message data is done by serialization formatters. .Net Remoting supports two formatters.
SOAP Formatter
Binary Formatter
SOAP Formatter converts objects into XML string whereas Binary Formatter converts an object's state into a binary stream. The binary serialization formatter is slightly faster.

12. What is the information required to configure remote
objects?

The following information to be provided to configure remote
object.
Activation type for the remote object
Channels URL of the remote object
Type metadata of the remote object

13. What is the difference between Debug Mode and Release Mode?

Debug Mode
Developer use debug mode for debugging the web application on live/local server. Debug mode allows developers to break the execution of the program using interrupt 3 and step through the code. Debug mode has below features:
1.Less optimized code
2. Some additional instructions are added to enable the developer to set a breakpoint on every source code line.
3. More memory is used by the source code at runtime.
4. Scripts & images downloaded by webresource.axd are not cached.
5. It has a big size and runs slower.
Release Mode
Developer use release mode for the final deployment of source code on live server. Release mode DLLs contain optimized code and it is for customers. Release mode has below features:
1.More optimized code
2. Some additional instructions are removed and the developer can’t set a breakpoint on every source code line.
3. Less memory is used by the source code at runtime.
4. Scripts & images downloaded by webresource.axd are cached.
5. It has a small size and runs fast.

14. Explain the different properties of Object-Oriented Systems.

An object-oriented system revolves around a class and objects. A class is used to describe characteristics of any entity of the real world. An object is a pattern of the class. An actual object created at runtime is called an instance. A class apart from characteristics has some functions to perform called as methods. For. e.g A class named “Food” has attributes like ‘price’, ‘quantity’. “Food” class has methods like Serve_food(), bill_food().
Objects in Object-Oriented Systems interact through messages.
Inheritance:- The main class or the root class is called as a Base Class. Any class which is expected to have ALL properties of the base class along with its own is called a Derived class. The process of deriving such a class is Derived class. For the “Food” class, a Derived class can be “Class Chinese food”.
Abstraction:- Abstraction is creating models or classes of some broad concept. Abstraction can be achieved through Inheritance or even Composition.
Encapsulation:- Encapsulation is a collection of functions of a class and object. The “Food” class is an encapsulated form. It is achieved by specifying which class can use which members (private, public, protected) of an object.
Polymorphism:- Polymorphism means existing in different forms. Inheritance is an example of Polymorphism. A base class exists in different forms as derived classes. Operator overloading is an example of a Polymorphism in which an operator can be applied in different situations.

15. Explain the use of encapsulation.

Encapsulation hides the internal state and behavior of an object. Encapsulation if used with access modifiers such as private, public, protected. It provides a way to protect data.
public class MyClass
{
private string name;
public string Name
{
get
{
return name;
}
set
{
name = value;
}
}
}
public class main
{
public static int Main(string[] args)
{
MyClass myclass = new MyClass();
myclass.name = "Communication";
Console.WriteLine("The name is :{0}", myclass.Name);
return 0;
}
}
See use of encapsulation through properties for accessing and setting the values.

16. Differentiate between instance data and class data?

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

17. Explain the use of static members with an example using C#.NET.

Static members are not associated with a particular instance of any class.
They need to be qualified with the class name to be called.
Since they are not associated with object instances, they do not have access to non-static members.
i.e.: "this" cannot be used, which represents the current object instance.

18. Describe the difference between Interface-oriented, Object-oriented and Aspect-oriented programming.

Interface oriented approach compels to develop the software based on the contract.
The 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.

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

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

20. How to add a ReadOnly property in C#.NET?

Properties can be made read-only by having only a get accessor in the implementation.
public class X
{
public X(int id)
{
x_id = id;
}
public int ID
{
get
{
return x_id;
}
}
}

21. Features of Static/Shared classes.

Static classes are used when any change made to an object should not affect the data and functions of the class. They can be used to create data and functions without the need for an instance.
Following are features of Static/Shared classes:-
-They can not be instantiated. By default, an object is created on the first method call to that object.
-Static/Shared classes can not be inherited.
-Static/Shared classes can have only static members.
-Static/Shared classes can have an only static constructor.

22. Difference between Association, Aggregation and Inheritance relationships.

An Association is a relationship between similar objects or objects with common structures.
Example:
An employee object is associated with the manager object.
Aggregation is “a part of” relationship.
Example:
A student object is a part of a College object.
Inheritance is a “is a “relationship where one or more classes are derived from a base class. The derived class has the base class plus its own characteristics.
Example:
French_Student class can be a derived class of student class.

23. Explain the features of an abstract class in NET?

An Abstract class is only used for inheritance. This means it acts as a base class for its derived classes. One cannot use it to create objects. When a class is declared as “Abstract”, it can only be inherited and not instantiated. MustInherit Keywords can be used to declare a class as abstract.
Abstract classes can also specify abstract members.

24. Similarities and differences between Class and structure in .NET.

Similarities:
Both Class and Structures can have methods, variables, and objects.
Both can have a constructor.
Both are user defined types.
Differences:
The structure is a value type, the variables cannot be assigned to NULL. On the other hand, classes being a reference type, a class variable can be assigned to NULL.
The structure is allocated on a stack when instantiated, while Class is allocated on a heap.
When a method is passed to a class, pass by reference is used. Pass by value is used for struts.
A class can have a destructor.

25. Explain the concepts and capabilities of the Assembly in .NET.

An assembly is a collection of files (dll’s, exe’s), group of resources that help in creating a logical unit of functionality. It forms the basic building block for deployment, reusability and security issues.
It provides a CLR environment.
It helps in maintaining security as it grants grant or denial of permissions.
When an application starts only assemblies the application initially calls must be present.
Assemblies can be either static or dynamic.
Assemblies help in resolving versioning issues.

26. Explain the concepts of CTS and CLS(Common Language Specification).

CTS
When different languages are integrated and want to communicate, it is certain that the languages have their own data types and different declaration styles. CTS defines how these different variables are declared and used in run time. E.g. VB offers an Integer data type while C++ offers long data type. Using CTS, these data types are converted to System32 which itself a data type of CLS.
CLS
Any language(s) that intend to use the Common Language Infrastructure needs to communicate with another CLS-Compliant language. This communication is based on a set of rules laid by CLS. These rules define a subset of CTS.

27. Difference between System exceptions and Application exceptions in .NET.

Application exceptions can be user defined exceptions thrown by the application. System exceptions are common exceptions thrown by the CLR. E.g. SqlException. System exceptions are very generic in nature and are used in almost all applications.

28. Difference between abstract classes and interfaces.

Following are the differences between abstract and interfaces:-
When a derived class is inherited from an Abstract class, no other class can be extended then. The interface can be used in any scenario. Abstract class contains an abstract method, i.e. actual implementation logic. On the other hand, interfaces have no implementation logic. Every method in an interface must be abstract. This is not necessary in the case of abstract classes.

29. What is the managed execution process?

The managed execution process is a process where CLR executes the managed code. The steps involved in this process are:
a. Choosing the right compiler
b. Compiling the code to MSIL. This also generates the required metadata.
c. Compile the MSIL code to native machine code.
d. Executing the code with a variety of services available.

30. Managed vs. unmanaged code

Managed code runs through a runtime which is a software layer that the application communicates due to which many functions are automatically done. Some of these functions are garbage collecting and exception handling.
A programmer needs to write many common functions in unmanaged code. So functions like garbage collecting, exception handling, etc have to be handled explicitly.

31. What is the difference between Problem, Issue, Bug, Error, and Defect?

Problem: Nothing but some difficult work to do.

Issue: It may be a bug, task, missing features.

Error: It is the Deviation from actual and the expected value.

defect: If tester found some issue then he will log as a defect

Bug: After login the defect by the tester, TL needs to review it and approve if it's really an issue, this is called Bug.

31. Difference between Constant and Read-only?

* Constant
Value never changed.
Declared and Initialized in Compile time.
By default, Constant is static, Cannot be declared as static.
* Read-Only
Value can be changed in the constructor of the class.
Declared and Initialized in Run time.
It can be declared as Static.

32. What is HTTP helper and how to implement it?

An ASP.NET HTTP handler is a process (frequently referred to as the "endpoint") that runs in response to a request made to an ASP.NET Web application. The most common handler is an ASP.NET page handler that processes .aspx files. When users request a .aspx file, the request is processed by the page through the page handler. You can create your own HTTP handlers that render custom output to the browser.
or
HTTP handlers are the .NET components that implement the System.Web.IHttpHandler interface. Any class that implements the IHttpHandler interface can act as a target for the incoming HTTP requests. HTTP handlers are somewhat similar to ISAPI extensions. One difference between HTTP handlers and ISAPI extensions is that HTTP handlers can be called directly by using their file name in the URL, similar to ISAPI extensions.
HTTP handlers implement the following methods.

Method Name Description
ProcessRequest This method is actually the heart of all Http handlers. This method is called to process Http requests.
IsReusable This property is called to determine whether this instance of Http handler can be reused for fulfilling another request of the same type. HTTP handlers can return either true or false in order to specify whether they can be reused.

33. What is hashtable?

The Hashtable class represents a collection of key-and-value pairs that are organized based on the hash code of the key. It uses the key to access the elements in the collection.

A hash table is used when you need to access elements by using the key, and you can identify a useful key value. Each item in the hash table has a key/value pair. The key is used to access the items in the collection.

34. Differences between Hashtable and Dictionary?

Dictionary:

It returns an error if we try to find a key that does not exist.
It is faster than a Hashtable because there is no boxing and unboxing.
Only public static members are thread-safe.
Dictionary is a generic type which means we can use it with any data type.

Hashtable:

It returns null if we try to find a key that does not exist.
It is slower than a dictionary because it requires boxing and unboxing.
All the members in a Hashtable are thread-safe,
Hashtable is not a generic type.

No comments: