What is partial classess in .net?
When there is a need to keep the business logic separate from the User Interface or when there is some class which is big enough to have multiple number of developers implement the methods in it, the class can be separated and written in different files as partial class.
The keyword partial must appear in each class.
//syntax for C#
Public partial class MyPartialClassOne
{
//code
}
// this code could be in one file
Public partial class MyPartialClassOne
{
//code
}
// this code could be in another file
What is the difference between overloading and overriding.
difference between overloading and overriding.
Overriding - Methods have the same signature as the parent class method.
Overloading - Methods have different parameters list or type or the return type.
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.
How does multi-threading work in .NET?
There are two main ways of multi-threading which .NET encourages:
To start your own threads with ThreadStart delegates, you should create a new thread "manually" for long-running tasks.
Using the ThreadPool class either directly (using ThreadPool.QueueUserWorkItem) or indirectly using asynchronous methods (such as Stream.BeginRead, or calling BeginInvoke on any delegate).
Use the thread pool only for brief jobs.
Benefits of using the Thread Pool.
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.
Whats the difference betweeen Structure, Class and Enumeration
Structures and Enumerations are Value-Types. This means, the data that they contain is stored as a stack on the memory. Classes are Reference-Types, means they are stored as a heap on the memory.
Structures are implicitly derived from a class called System.ValueType. The purpose of System.ValueType is to override the virtual methods defined by System.Object. So when the runtime encounters a type derived from System.ValueType, then stack allocation is achieved. When we allocate a structure type, we may also use the new keyword. We may even make a constructor of a structure, but, remember, A No-argument constructor for a structure is not possible. The structure's constructor should always have a parameter.
So if we define the following structure
struct MyStruct
{
public int y,z;
}
and we create a structure type
MyStruct st = new MyStruct();
In case of a class, no-argument constructors are possible. Class is defined using the class keyword.
A struct cannot have an instance field, whereas a class can.
class A
{
int x = 5; //No error
...
}
struct
{
int x = 5; //Syntax Error
}
A class can inherit from one class (Multiple inheritance not possible). A Structure cannot inherit from a structure.
Enum is the keyword used to define an enumeration. An enumeration is a distinct type consisting of a set of named constants called the enumerator list. Every enumeration has an underlying type. The default type is "int". Note: char cant be the underlying data type for enum. First value in enum has value 0, each consequent item is increased by 1.
enum colors {red, green, blue, yellow};
Here, red is 0, green is 1, blue is 2 and so on.
An explicit casting is required to convert an enum value to its underlying type
int x = (int)colors.yellow;
What is the difference between Shared and Static?
They both mean the same. Shared is used in VB.NET. Static is used in C#.
When the static keyword is used to declare a class, the member in context must be directly invoked from the class, rather than from the instance. Consider the following example
//Consider writing the following line of code...
Console obj = new Console();
obj.Writeline("Vishal likes static members"); //This line does'nt print
//This does'nt work, because WriteLine is a static method defined in the class Console
//The Console class is a static class
To use static members, give a reference to the exact class, as an instance in this case won't work.
To make this work, write...
Console.Writeline("Vishal likes static members");
To work with members of static classes, no need to create their instances.
Static Member - A class member declared with the keyword static is a static member. A static member is owned by the class, not by its instances (objects of the class).
Note that static members are actually class members, while non-static members are instance members (means they are owned by the instances). Both in C# & VB.NET, we may create static/shared events, properties, fields and functions.
Note Indexers in C# cannot be declared static.
Note Static member functions cannot access non-static members directly.
Questions on XSLT and xPath in .NET
Define XSLT.
XSLT language is used for transforming XML documents into XHTML documents. It also transforms XML into another XML document.
What is XPATH?
XPath is a language that is used to navigate through XML documents.It can find information in an XML document like elements and attributes.
Define XMLReader Class.
The XMLReader Class (Assembly: System.Xml.dll) represents a reader that provides fast, non-cached, forward-only access to XML data.
Define XMLValidatingReader class.
The XMLValidatingReader class (Assembly: System.Xml.dll) represents a reader that provides:
- Document type definition (DTD),
- XML-Data Reduced (XDR) schema, and
- XML Schema definition language (XSD) validation