Académique Documents
Professionnel Documents
Culture Documents
Assembly Questions
1.How is the DLL Hell problem solved in .NET?
Ans. Assembly versioning allows the application to specify
not only the library it needs to run (which was available
under Win32), but also the version of the assembly.
2.What are the ways to deploy an assembly?
Ans. An MSI installer, a CAB archive, and XCOPY command.
Questions...
class AClass
{
int aField;
}
class MainClass
{
public static void Main()
{
AClass b = null; // No error.
AStruct s = null; // Error
/* [ Cannot convert null to 'AStruct' because it is
a value type ].*/
}
}
When you instantiate a class, it will be allocated on the heap.When you instantiate a
struct, it gets created on the stack. You will always be dealing with reference to an
object ( instance ) of a class. But you will not be dealing
with references to an instance of a struct ( but dealing directly with them ).
class MyClass
{
int myVar =10; // no syntax error.
public void MyFun( )
{
// statements
}
}
struct MyStruct
{
int myVar = 10; //syntax error
public void MyFun( )
{
// statements
}
}
class MyClass
{
int myVar = 10;
public MyClass( ) // no syntax error.
{
// statements
}
}
struct MyStruct
{
int myVar;
public MyStruct( ) // syntax error.
{
// statements
}
}
Classes must be instantiated using the new operator. But structs can be instantiated
without using the new operator.
MyClass aClassObj;
/* MyClass aClassObj=new MyClass(); is the correct
format.aClassObj.myVar=100;//NullReferenceException
(because aClassObj does not contain a reference to an object
of type myClass). */
Classes support inheritance.But there is no inheritance for structs. ( structs don't support
inheritance polymorphism )
(1)
struct MyStruct
{
int aStructVar;
internal void aStructMethod()
{
// statements
}
}
(2)
class MyClass
{
int aClassVar;
int aClassMethod()
{
// statements
}
}
struct MyStruct
{
int myInt;
public MyStruct( )
{ } ~MyStruct( ) //Error.
{
Console.WriteLine("Destructor of MyStruct object");
}
}
class MyClass
{
int myInt;
public MyClass( ) { } ~MyClass( ) // No Error.
{
Console.WriteLine("Destructor of MyClass object"); }
}
Classes are used for complex and large set data. structs are
simple to use. structs are useful whenever you need a type that will be used often and is
mostly just a piece of data.
An example below...
// .NET Singleton
sealed class Singleton
{
private Singleton() {}
public static readonly Singleton Instance = new Singleton();
}
Obviously you'd need to add some properties and methods to get something useful, but
you get the idea. Watch out for
thread safety issues.
This link may give more insight: ttp://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpatterns/html/ImpSingletonInCsharp.asp
If you want to pass state from the source page to the new
page, you have to pass it either on the URL (such as a database key, or message string), or you can store it
in the Session
object (caveat: there may be more than one browser window, and they’ll all use the same session object).
Response.Redirect("new.aspx?id=32", true);
Transfer: A transfer happens without the client knowing
– it’s the equivalent of a client requesting one page,
but being given another. As far as the client knows, they
are still visiting the original URL.
The .NET components, which make use of the COM+ Services, are termed as ServicedComponents. Must
read this link to learn more : http://msdn2.microsoft.com/en-us/library/ms973809.aspx
Number of Tables
A recordset looks like a single table. If a recordset is to contain data from multiple database tables, it must
use a JOIN query, which assembles the data from the various database tables into a single result table. In
contrast, a dataset is a collection of one or more tables. The tables within a dataset are called data tables;
specifically, they are DataTable objects. If a dataset contains data from multiple database tables, it will
typically contain multiple DataTable objects. That is, each DataTable object typically corresponds to a
single database table or view. In this way, a dataset can mimic the structure of the underlying database.
A dataset usually also contains relationships. A relationship within a dataset is analogous to a foreign-key
relationship in a database —that is, it associates rows of the tables with each other. For example, if a
dataset contains a table about investors and another table about each investor's stock purchases, it could
also contain a relationship connecting each row of the investor table with the corresponding rows of the
purchase table. Because the dataset can hold multiple, separate tables and maintain information about
relationships between them, it can hold much richer data structures than a recordset, including self-relating
tables and tables with many-to-many relationships.
A cursor is a database element that controls record navigation, the ability to update data, and the visibility
of changes made to the database by other users. ADO.NET does not have an inherent cursor object, but
instead includes data classes that provide the functionality of a traditional cursor. For example, the
functionality of a forward-only, read-only cursor is available in the ADO.NET DataReader object. For
more information about cursor unctionality, see Data Access Technologies.
There is one significant difference between disconnected processing in ADO and ADO.NET. In ADO you
communicate with the database by making calls to an OLE DB provider. In ADO.NET you communicate
with the database through a data adapter (an OleDbDataAdapter, SqlDataAdapter, OdbcDataAdapter, or
OracleDataAdapter object), which makes calls to an OLE DB provider or the APIs provided by the
underlying data source. The important difference is that in ADO.NET the data adapter allows you to
control how the changes to the dataset are transmitted to the database — by optimizing for performance,
performing data validation checks, or adding any other extra processing.
Note - Data adapters, data connections, data commands, and data readers are the components that make up
a .NET Framework data provider. Microsoft and third-party providers can make available other .NET
Framework data providers that can be integrated into Visual Studio. For information on the different .NET
Data providers, see .NET Data Providers.
12. Can you give an example of what might be best suited to place in the Application_Start and
Session_Start subroutines?
Ans. The Application_Start event is guaranteed to occur only once throughout the lifetime of the
application. It’s a good place to initialize global variables. For example, you might want to retrieve a list of
products from a database table and place the list in application state or the Cache object.
SessionStateModule exposes both Session_Start and Session_End events.
Polymorphism by definition means taking many forms. In C# it means the ability for classes to share the
same methods (actions) but implement them differently. For instance, say we create a class called "Shape"
and this class has a method called .draw() which draws the shape onto the user interface. Then we create
two subclasses, using inheritance, of this Shape class. One called Square, the other called Circle. Now
obviously a square and circle are two entirely different shapes, yet both classes have the .draw() method.
When the Square.draw() method is called it will draw a square on the user interface. When the
Circle.draw() method is called, it will draw a circle on the user interface. So both classes can use the same
methods but implement them differently.
16. Can you explain what inheritance is and an example
of when you might use it?
Ans. Inheriting a trait from a parent class!
Use the existing functionality along with its own
properities.
Ans. Inline function bind at compile time can write in aspx page with in <% %> .
20. Explain what a diffgram is, and a good use for one.
Ans. A DiffGram is an XML format that is used to identify
current and original versions of data elements. The DataSet uses the DiffGram format to
load and persist its contents, and to serialize its contents for transport across a network
connection. When a DataSet is written as a DiffGram, it populates the DiffGram with all
the necessary information to accurately recreate the contents, though not the schema, of
the DataSet, including column values from both the Original and Current row versions,
row error information, and row order. When sending and retrieving a DataSet from an
XML Web service, the DiffGram format is implicitly used.
Additionally, when loading the contents of a DataSet from
XML using the ReadXml method, or when writing the
contents of a DataSet in XML using the WriteXml method,
you can select that the contents be read or written as a
DiffGram
DiffGram Format
The DiffGram format is divided into three sections: the
current data, the original (or "before") data, and an
errors section, as shown in the following example.
<?xml version="1.0"?>
<diffgr:diffgram
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<DataInstance>
</DataInstance>
<diffgr:before>
</diffgr:before>
<diffgr:errors>
</diffgr:errors>
</diffgr:diffgram>
The DiffGram format consists of the following blocks of data:
<DataInstance>
The name of this element, DataInstance, is used for
explanation purposes in this documentation. A DataInstance
element represents a DataSet or a row of a DataTable.
Instead of DataInstance, the element would contain the name
of the DataSet or DataTable. This block of the DiffGram format contains the current data,
whether it has been modified or not.
An element, or row, that has been modified is identified with
the diffgr:hasChanges annotation.
<diffgr:before>
This block of the DiffGram format contains the original
version of a row. Elements in this block are matched to
elements in the DataInstance block using the diffgr:id
annotation.
<diffgr:errors>
This block of the DiffGram format contains error information
for a particular row in the DataInstance block. Elements in
this block are matched to elements in the DataInstance block
using the diffgr:id annotation.
24. Whats MSIL, and why should my developers need an appreciation of it if at all?
Ans. Microsoft Intermediate language. which is the out put
for all the .net supported languages after compilation will
produce. Appreciation is for cross language support.
Definition:Microsoft Intermediate Language (MSIL) is the
CPU-independent instruction set generated by .NET compilers
from .NET languages such as J#, C# or Visual Basic. MSIL is
compiled before or during execution of the program by a Virtual Execution System
(VES), which is part of the Common Language Runtime module (CLR).
25. In what order do the events of an ASPX page execute. As a developer is it
important to undertsand these events?
Ans.
Page request
The page request occurs before the page life cycle begins.
When the page is requested by a user, ASP.NET determines
whether the page needs to be parsed and compiled (therefore beginning the life of a
page), or whether a cached version
of the page can be sent in response without running the page.
Start
In the start step, page properties such as Request and
Response are set. At this stage, the page also determines
whether the request is a postback or a new request and sets
the IsPostBack property. Additionally, during the start step,
the page's UICulture property is set.
Page initialization
During page initialization, controls on the page are
available and each control's UniqueID property is set. Any
themes are also applied to the page. If the current request is
a postback, the postback data has not yet been loaded and
control property values have not been restored to the values
from view state.
Load
During load, if the current request is a postback, control
properties are loaded with information recovered from view
state and control state.
Validation
During validation, the Validate method of all validator
controls is called, which sets the IsValid property of
individual validator controls and of the page.
Unload
Unload is called after the page has been fully rendered, sent
to the client, and is ready to be discarded. At this point,
page properties such as Response and Request are unloaded and any cleanup is
performed.
30. What property must you set, and what method must you call in your code, in
order to bind the data from some data source to the Repeatercontrol?
Ans. Datasource, DataBind
33. How do you turn off cookies for one page in your site?
Ans. Disablecookies.
Response.Cookies("Name") = "Nigel"
Response.Cookies("Name").Expires = DateAdd("m", 1, Now())
It’s that easy! Nothing more to it. You have now set a permanent cookie on your
computer. Also, note that whenever the above code is called the expiration date of the
cookie is renewed by one month from now.
There are a few more options which you can set, like for example the Path option. You
can limit cookies to certain paths on your website, so you can set several cookies with the
same name, as long as they belong to different paths. To do this, you would use the
following code (extending the previous code):
Response.Cookies("Name").Path = "/foo/"
The above code would limit the cookie to the path foo. It is
also possible to assign multiple values to a particular cookie.
This is done using the so-called dictionary functionality of
a cookie. For example, if I’d want to store not only the first
name, but also the surname in my Name cookie, I’d be using
something like the following code:
Response.Cookies("Name")("First") = "Nigel"
Response.Cookies("Name")("Last") = "Pallett"
Response.Cookies("Name").Expires = DateAdd("m", 1, Now())
That’s all! Although there are a few more "advanced" options,
such as the Secure option and the Domain option, it is of no use now.
Retrieving Cookies
Retrieving the value of cookies is a very easy job, because
again everything is handled by the browser and your server.
All you have to use is ASP’s inbuilt functions.
There is no difference in retrieving a Session cookie or a
permanent cookie, and in both cases you use the following code:
The above is for when you assigned only one value to a cookie. If you assigned multiple
values you a cookie, you use the following code:
44. Where on the Internet would you look for Web services?
Ans. UDDI
45. What tags do you need to add within the
asp:datagrid tags to bind columns manually.
Ans. Autogenerate columns
46. Which property on a Combo Box do you set with a column name, prior to
setting the DataSource, to display data in the combo box?
Ans. Datatext, Datavalue
47. How is a property designated as read-only?
Ans.
In VB.NET:
Public ReadOnly Property PropertyName As ReturnType
Get ‘Your Property Implementation goes in here
End Get
End Property
In C#
public returntype PropertyName
{
get{
//property implementation goes here
}
// Do not write the set implementation
}
48. Which control would you use if you needed to make sure the values in two
different controls matched?
Ans. Ideally we would tend to use Comparefield validator.
49. True or False: To test a Web service you must create a windows application or
Web application to consume this service?
Ans. False