Showing posts with label answers. Show all posts
Showing posts with label answers. Show all posts
Thursday, 13 March 2014
ASP.NET Interview Questions and Answers (3.5)
Asp.net Interview Questions and Answers (3.5)
What is the Windows Presentation Foundation
Answer :: The
Windows Presentation Foundation is the unified presentation subsystem for
Windows. It
consists of a display engine and a
managed-code framework. The Windows Presentation Foundation unifies
how Windows creates, displays, and
manipulates documents, media, and user interface, which enables
developers and designers to create
visually-stunning, differentiated user experiences that improve customer
connection. When it ships, scheduled for
2006, the Windows Presentation Foundation will be available on
Windows XP, Windows Server 2003 and all
future releases of the Windows operating system. When delivered,
the Windows Presentation Foundation will
become Microsoft’s strategic user interface technology.
What is XAML
Answer :: XAML, Extensible Application Markup
Language, is Microsoft’s XML-based language for
creating a rich graphical user
interface....XAML was introduced in 2003 as the language behind Windows
Presentation Foundation, then known as Avalon.
What is the Windows Presentation Foundation
Answer :: The Windows Communication
Foundation is a set of technologies for building and running connected
systems.
The Windows Communication Foundation is a new
breed of communications infrastructure built around the
Web services architecture. Advanced Web
services support in the Windows Communication Foundation
provides secure, reliable, and transacted
messaging along with interoperability. The Windows Communication
Foundation’s service-oriented
programming model is built on the .NET Framework and simplifies
development of connected systems. The Windows
Communication Foundation unifies a broad array of
distributed systems capabilities in an
extensible architecture, spanning transports, security systems, messaging
patterns, encodings, network topologies and
hosting models. The Windows Communication Foundation will be
an integral capability of Windows Vista and
will also be supported on Windows XP and Windows Server 2003.
Microsoft has also done significant work to
integrate the Windows Communication Foundation with existing
Microsoft technologies for building
distributed systems including COM+, MSMQ, and ASP.NET Web services.
Applications built with those existing technologies
can now be exposed as services without modification to the
application. This infrastructure-level
solution greatly assists developers in exposing existing applications as
services. The Windows Communication
Foundation also provides simple and mechanical mechanisms to
migrate applications that use .NET remoting,
ASP.NET Web services, and .NET Enterprise Services to natively
use the Windows Communication Foundation
programming model.
Describe the usefulness Visual Studio 2008
Split View feature?
Answer :: Visual Studio allows you to set the
default view (Split, Source or Design) and to choose between a
horizontal split and a vertical split.
Especially this last option is very handy when you have a widescreen
monitor.
To enable vertical split-view orientation in
VS 2008, select the tools->options menu item and go to the HTML
Designer->General section. Then check
the "Split views vertically" checkbox:
Can you compare Nested Master Page Support in
Visual Studio 2008 as compared to VS 2005?
Answer :: Already Visual Studio 2005 supports
nested master pages concept with .NET 2.0, but the problem
with this Visual Studio 2005 that pages based
on nested masters can't be edited using WYSIWYG web
designer. But now in VS 2008 you can even
edit the nested master pages.
What is a Nested Master Page and how will you
use it ?
Answer :: Master pages can be nested, with
one master page referencing another as its master. Nested master
pages allow you to create componentized
master pages. For example, a large site might contain an overall
master page that defines the look of the site.
Different site content partners can then define their own child
master pages that reference the site master
and that in turn define the look for that partner's content.
A child master page has the file name
extension .master, as with any master page. The child master page
typically contains content controls that are
mapped to content placeholders on the parent master page. In this
respect, the child master page is laid out
like any content page. However, the child master page also has
content placeholders of its own to display
content supplied by its own child pages. The following three page
listings show a simple nested master page
configuration.
What is the enhanced ajax support for Asp.net
in 3.5 as compared to the previous versions of Asp.net ?
Answer :: Previously developer has to install
AJAX control library separately that does not come from VS, but
now if you install Visual Studio 2008, you
can built-in AJAX control library. This Ajax Library contains plenty of
rich AJAX controls like Menu, TreeView,
webparts and also these components support JSON and VS 2008
contains in built ASP.NET AJAX Control
Extenders.
What is VS 2008 Multi-Targeting
Answer :: Earlier you were not able to
working with .NET 1.1 applications directly in visual studio 2005. Now in
Visual studio 2008 you are able to create,
run, debug the .NET 2.0, .NET 3.0 and .NET 3.5 applications. You
can also deploy .NET 2.0 applications in the
machines which contains only .NET 2.0 not .NET 3.x.
C# interview Questions and Answers
C# interview Questions and Answers :
What
is the syntax to inherit from a class in C#?
Place
a colon and then the name of the base class. Example: class MyNewClass :
MyBaseClass
Can
you prevent your class from being inherited by another class?
Yes.
The keyword “sealed” will prevent the class from being inherited.
Can
you allow a class to be inherited, but prevent the method from being
overridden?
Yes.
Just leave the class public and make the method sealed.
What’s
an abstract class?
A
class that cannot be instantiated. An abstract class is a class that must be
inherited and
have
the methods overridden. An abstract class is essentially a blueprint for a
class
without
any implementation.
When
do you absolutely have to declare a class as abstract?
1.
When the class itself is inherited from an abstract class, but not all base
abstract
methods
have been overridden.
2.
When at least one of the methods in the class is abstract.
What
is an interface class?
Interfaces,
like classes, define a set of properties, methods, and events. But unlike
classes,
interfaces
do not provide implementation. They are implemented by classes, and defined
as
separate entities from classes.
Why
can’t you specify the accessibility modifier for methods inside the interface?
They
all must be public, and are therefore public by default.
Can
you inherit multiple interfaces?
Yes.
.NET does support multiple interfaces.
What
happens if you inherit multiple interfaces and they have conflicting method
names?
It’s
up to you to implement the method inside your own class, so implementation is
left
entirely
up to you. This might cause a problem on a higher-level scale if similarly
named
methods
from different interfaces expect different data, but as far as compiler cares
you’re okay. To Do: Investigate
What’s
the top .NET class that everything is derived from?
System.Object.
What
does the term immutable mean?
The
data value may not be changed. Note: The variable value may be changed, but the
original
immutable data value was discarded and a new data value was created in
memory.
What’s
the difference between System.String and System.Text.StringBuilder
classes?
System.String
is immutable. System.StringBuilder was designed with the purpose of
having
a mutable string where a variety of operations can be performed.
What’s
the advantage of using System.Text.StringBuilder over System.String?
StringBuilder
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.
Can
you store multiple data types in System.Array?
No.
What’s
the difference between the System.Array.CopyTo() and
System.Array.Clone()?
The
Clone() method returns a new array (a shallow copy) object containing all the
elements
in the original array. The CopyTo() method copies the elements into another
existing
array. Both perform a shallow copy. A shallow copy means the contents (each
array
element) contains references to the same object as the elements in the original
array.
A
deep copy (which neither of these methods performs) would create a new instance
of
each
element's object, resulting in a different, yet identacle object.
How
can you sort the elements of the array in descending order?
By
calling Sort() and then Reverse() methods.
What’s
the .NET collection class that allows an element to be accessed using a
unique
key?
HashTable.
What
class is underneath the SortedList class?
A
sorted HashTable.
Will
the finally block get executed if an exception has not occurred?
Yes.
What’s
the C# syntax to catch any possible exception?
A
catch block that catches the exception of type System.Exception. You can also
omit the
Wednesday, 12 March 2014
Multi-Threading Concept in c#(Questions and answers)
Multi-Threading Concept in c# (Questions and answers)
Multithreading is the ability of an operating system to
concurrently run programs that have been divided into threads.
Multithreading offers better utilization of processors and
other system resources.
Example:
A program can spell check and save the data to disk while
sending data to be printed.
Advantages and disadvantages of using multithreading
Advantages:
Simultaneous access to multiple applications
Reduced number of required servers
Improved performance and concurrency
Simplified coding of remote procedure calls and
conversations
Disadvantages:
Code writing, debugging, managing concurrency, testing,
porting existing code is difficult in multithreading and multicontexting.
Programmers need to remove static variables and replace any
code that is not thread-safe to introduce threading into a previously non
threaded application.
Benefits of using the Thread Pool.
The benefits of using a Thread Pool are:
Thread creation and destruction overhead is negated,
Better performance and better system stability.It is better to use a thread pool in cases where the number of threads is very large.
Explain how to create and manage threads using Thread
class in the System.Threading namespace in .NET.
using System.Threading;
private void ThreadTask()
{
int x;
int val;
Random r=new
Random();
while(true)
{
x=this.progressBar1.Step*r.Next(-1,2);
val =
this.progressBar1.Value + x;
if (val
> this.progressBar1.Maximum)
val
= this.progressBar1.Maximum;
else if
(val < this.progressBar1.Minimum)
val
= this.progressBar1.Minimum;
this.progressBar1.Value = val;
Thread.Sleep(100);
}
}
You need to write these lines first:
Thread t1 = new
Thread(new ThreadStart(this.ThreadTask));
t1.IsBackground =
true;
t1.Start();
Explain the purpose of Mutex class in .NET.
System uses synchronization mechanism to make sure that a
resource is used by only one thread at a time when more than one thread needs
to access a shared resource at the same time.
Mutex grants exclusive access to the shared resource to a
single thread.
A second thread that needs to acquire a particular mutex is
suspended until the first thread releases the mutex.
Describe the concepts of Monitor class, the interlocked
class and the ReaderWriterLock class.
Access to objects by is controlled by the Monitor class. It
grants a lock for an object to a single thread.
Critical sections can be access restricted by using object
locks.
While a thread owns the lock for an object, no other thread
can acquire that lock.
Interlocked class provides atomic operations for variables
that are shared by multiple threads.
When two threads are executing concurrently on separate
processors error protection is done.
The methods of this class help protect against errors that
can occur when the scheduler switches contexts while a thread is updating a
variable that can be accessed by other threads.
ReaderWriterLock synchronizes access to a resource. It
allows either concurrent read access for multiple threads, or write access for
a single thread.
A ReaderWriterLock provides better throughput than a simple
one lock a time like Monitor.
Explain about Serialization in .NET. Explain binary
serialization and XML serialization
System.Runtime.Serialization namespace provides
Serialization in .NET.
The IFormatter interface in the namespace contains Serialize
and De-serialize methods that save and load data of a stream.
So we need stream as a container for the serialized
object(s) and a formatter that serializes these objects onto the stream to
implement serialization in .net.
Binary serialization is a mechanism that creates exact
binary copy of the object onto the storage media by writing the data to the
output stream such that it can be used to re-construct the object
automatically.
XML serialization results in strongly typed classes with
public properties and fields that are converted to a serial format for storage
or transport. This XML stream conforms to a specific XML Schema definition
language (XSD) document.
Explain why Serialization.
An object is stored in a file, a database or even in the
memory. However, data to be transferred over a network needs to be in a linear
form for which serialization and deserialization are used.
Advantage of serialization is the ability of an object to be
serialized into a persistent or a non-persistent storage media and then
reconstructing the same object later by de-serializing the object.
Remoting and Web Services depend heavily on Serialization
and De-serialization.
Explain the components that comprise the binary
serialization architecture.
To binary serialize an object we need a FileStream object,
Constructor: FileStream(file_name, FileMode.Create);
And
BinaryFormatter
Constructor: binaryFormatter.Serialize(fileStreamObject,
object1);
What is Formatters? Explain the binary formatter and the
SOAP formatter.
A formatter determines the serialization format for objects.
.NET framework provides Binary formatter and SOAP formatter
which inherit from the IFormatter interface
The Binary Formatter
It provides binary encoding for compact serialization for
storage or socket-based network streams.
It is not appropriate for data to be passed through a
firewall.
The SOAP Formatter
It provides formatting that can be used to enable objects to
be serialized using the SOAP protocol.
The class is used for serialization through firewalls or
diverse systems.
What are the main advantages of binary serialization?
An object is stored in a file, a database or even in the
memory. However, data to be transferred over a network needs to be in a linear
form for which serialization and deserialization are used.
Advantage of serialization is the ability of an object to be
serialized into a persistent or a non-persistent storage media and then
reconstructing the same object later by de-serializing the object.
Also Binary Serialization is faster, supports complex
objects too with read only properties and even circular references.
How do you encapsulate the binary serialization?
public static void SerializeBinary( object o, string
file_name)
{
using (FileStream
fs = new FileStream(file_name, FileMode.Create)) {
BinaryFormatter fmt
= new BinaryFormatter ();
fmt.Serialize(fs,
o);
}
}
How do you implement a custom serialization?
CUSTOM SERIALIZATION implementation
public class A: ISerializable
{
private int
a;
protected
A(SerializationInfo si, StreamingContext sc)
{
this.a = serializationInfo.GetInt32("a");
}
public void
ISerializable.GetObjectData(SerializationInfo si, StreamingContext sc)
{
si.AddValue("a", this.a);
}
}
What is the difference between the SoapFormatter and the
XmlSerializer?
SoapFormatter
SOAP formatter will actually take the field values of an
object and store all of that information in the stream passed.
SoapFormatter is better to serialize arbitrary data
XmlSerializer
XML Serialization would just serialize the public properties
of an object.
The XML Serializer is used typically for serializing simple
types across web services
xmlserializer is better, more flexible and faster
How can I optimize the serialization process?
The first call to a Web Service takes long because
XmlSerializer generate an assembly optimized for each type in memory.
To optimize the serialization process pregeneration of
serialization assembly with Visual Studio or sgen.exe is needed.
Implementing serialization separately can also increase the
performance.
Apartments
COM objects in the process as divided into groups called
apartments. A COM object lives in exactly one apartment, in the sense that its
methods can legally be directly called only by a thread that belongs to that
apartment. Any other thread that wants to call the object must go through a
proxy.
There are two types of apartments: single-threaded
apartments, and multithreaded apartments.
1.Single-threaded Apartments—Single-threaded
apartments consist of exactly one thread, so all COM objects that live in a
single-threaded apartment can receive method calls only from the one thread
that belongs to that apartment. All method calls to a COM object in a
single-threaded apartment are synchronized with the windows message queue for
the single-threaded apartment's thread. A process with a single thread of
execution is simply a special case of this model.
2. Multithreaded Apartments—Multithreaded apartments
consist of one or more threads, so all COM objects that live in an
multithreaded apartment can receive method calls directly from any of the
threads that belong to the multithreaded apartment. Threads in a multithreaded
apartment use a model called free-threading. Calls to COM objects in a
multithreaded apartment are synchronized by the objects themselves.
Synchronizing objects
Lock
Locks are useful when only one thread at a time can be
allowed to modify data or some other controlled resource.
Monitors
Monitors are Like the lock keyword, monitors prevent blocks
of code from simultaneous execution by multiple threads. The Enter method
allows one and only one thread to proceed into the following statements; all
other threads are blocked until the executing thread calls Exit. This is just
like using the lock keyword. In fact, the lock keyword is implemented with the
Monitor class.
Mutex
A mutex is similar to a monitor; it prevents the
simultaneous execution of a block of code by more than one thread at a time. In
fact, the name "mutex" is a shortened form of the term "mutually
exclusive." Unlike monitors, however, a mutex can be used to synchronize
threads across processes.
Semaphore is same as Mutex but it ensures not more than a
specified number of threads can access a resource, or section of code.
Subscribe to:
Posts (Atom)