Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Net
C# allows multiple interface inheritance. It means that a class can implement more than one
interface. The methods declared in an interface are implicitly abstract. If a class implements an
interface, it becomes mandatory for the class to override all the methods declared in the interface,
otherwise the derived class would become abstract.
Can you explain what inheritance is and an example of when you might use it?
The savingaccount class has two data members-accno that stores account number, and trans
that keeps track of the number of transactions. We can create an object of savingaccount class
as shown below.
We can write our own definition of a method that already exists in a base class. This is called
method overriding. We have overridden the deposit( ) and withdraw( ) methods in the
savingaccount class so that we can make sure that each account maintains a minimum balance
of Rs. 500 and the total number of transactions do not exceed 10. From these methods we have
called the base class's methods to update the balance using the base keyword. We have also
overridden the display( ) method to display additional information, i.e. account number.
Unlike C++, C# does not support multiple inheritance. So, in C# every class has exactly one base
class.
Now, suppose we declare reference to the base class and store in it the address of instance of
derived class as shown below.
If we don't want to override base class's virtual method, we can declare it with new modifier in
derived class. The new modifier indicates that the method is new to this class and is not an
override of a base class method.
In C#
Private DataType mPropertyName;
public returntype PropertyName
{
get{
//property implementation goes here
return mPropertyName;
}
// Do not write the set implementation
}
Hiding is also called as Shadowing. This is the concept of Overriding the methods. It is a concept
used in the Object Oriented Programming.
E.g.
public class ClassA {
public virtual void MethodA() {
Trace.WriteLine("ClassA Method");
}
}
Why is the XML InfoSet specification different from the Xml DOM? What does the InfoSet
attempt to solve?
"The XML Information Set (Infoset) defines a data model for XML. The Infoset describes the
abstract representation of an XML Document. Infoset is the generalized representation of the
XML Document, which is primarily meant to act as a set of definitions used by XML technologies
to formally describe what parts of an XML document they operate upon.
The Document Object Model (DOM) is one technology for representing an XML Document in
memory and to programmatically read, modify and manipulate a xml document.
Infoset helps defining generalized standards on how to use XML that is not dependent or tied to a
particular XML specification or API. The Infoset tells us what part of XML Document should be
considered as significant information.
Contrast DTDs versus XSDs. What are their similarities and differences? Which is
preferred and why?
Document Type Definition (DTD) describes a model or set of rules for an XML document. XML
Schema Definition (XSD) also describes the structure of an XML document but XSDs are much
more powerful.
The disadvantage with the Document Type Definition is it doesn’t support data types beyond the
basic 10 primitive types. It cannot properly define the type of data contained by the tag.
An Xml Schema provides an Object Oriented approach to defining the format of an xml
document. The Xml schema support most basic programming types like integer, byte, string, float
etc., We can also define complex types of our own which can be used to define a xml document.
Xml Schemas are always preferred over DTDs as a document can be more precisely defined
using the XML Schemas because of its rich support for data representation.
What happens when you encounter a continue statement inside the for loop?
The code for the rest of the loop is ignored, the control is transferred back to the beginning of the
loop.
How can you sort the elements of the array in descending order?
By calling Sort() and then Reverse() methods.
Will finally block get executed if the exception had not occurred?
Yes.
What's the C# equivalent of C++ catch (…), which was a catch-all statement for any
possible exception?
A catch block that catches the exception of type System.Exception. You can also omit the
parameter data type in this case and just write catch {}.
How do you generate documentation from the C# file commented properly with a
command-line compiler?
Compile it with a /doc switch.
What's the implicit name of the parameter that gets passed into the class' set method?
Value, and it's datatype depends on whatever variable we're changing.
Why is it not a good idea to insert code into InitializeComponent method when working
with Visual Studio?
The designer will likely through it away, most of the code inside InitializeComponent is auto-
generated.
An array has a rank that determines the number of indices associated with each array element.
The rank of an array is also referred to as the dimensions of the array. An array with a rank of one
is called a single-dimensional array. An array with a rank greater than one is called a multi-
dimensional array. Specific sized multidimensional arrays are often referred to as two-
dimensional arrays, three-dimensional arrays, and so on.
When you create a jagged array you declare the number of rows in your array. Each row will hold
an array that will be on any length. Before filling the values in the inner arrays you must declare
them.
Note that while declaring the array the second dimension is not supplied because this you will
declare later on in the code.
Jagged array are created out of single dimensional arrays so be careful while using them. Don’t
confuse it with multi-dimensional arrays because unlike them jagged arrays are not rectangular
arrays.
What is a delegate, why should you use it and how do you call it ?
A delegate is a reference type that refers to a Shared method of a type or to an instance method
of an object. Delegate is like a function pointer in C and C++. Pointers are used to store the
address of a thing. Delegate lets some other code call your function without needing to know
where your function is actually located. All events in .NET actually use delegates in the
background to wire up events. Events are really just a modified form of a delegate.
It should give you an idea of some different areas in which delegates may be appropriate:
If you define integer variable and a object variable and a structure then how those will be
plotted in memory.
[C#]
[Serializable]
public struct Int32 : IComparable, IFormattable, IConvertible
So , it’s a struct by definition , which is the same case with various other value types .
Object – Base class , that is by default reference type , so at runtime JIT compiler allocates
memory on the “Heap” Data structure .
Reference types are defined as class , derived directly or indirectly by System.ReferenceType