Interactive SQL tutorial, learn about: SQL Server , Oracle , MySQL , DB2 , Mimer , PostgreSQL , SQLite and Access .
By Andrew Cumming of the School of Computing of Napier University, Edinburgh, UK. 1999-2005 |
Thursday, August 28, 2008
SQL Zoo net
Interview Question of Asp.net
How do we do a case-insensitive string comparison?
Answer: Use the String.Compare function. Its third parameter is a boolean which specifies whether case should be ignored or not.
"skp" == "Skp" // false
System.String.Compare( "skp", "Skp", true ) // true
Does C# support a variable number of arguments?
Answer: Yes, using the params keyword. The arguments are specified as a list of arguments of a specific type, e.g. int. For ultimate flexibility, the type can be object. The standard example of a method which uses this approach is System.Console.WriteLine().
How can we process command-line arguments?
Answer: Like this:
using System;
class CApp
{
public static void Main( string[] args )
{
Console.WriteLine( "You passed the following arguments:" );
foreach( string arg in args )
Console.WriteLine( arg );
}
}
Does C# do array bounds checking?
Answer: Yes. An IndexOutOfRange exception is used to signal an error.
How can we make sure our C# classes will interoperate with other .NET languages?
Answer: Make sure our C# code conforms to the Common Language Subset (CLS). To help with this, add the [assembly:CLSCompliant(true)] global attribute to your C# source files. The compiler will emit an error if you use a C# feature which is not CLS-compliant.
How do we use the 'using' keyword with multiple objects?
Answer: We can nest using statements, like this:
using( obj1 )
{
using( obj2 )
{
...
}
}
However consider using this more aesthetically pleasing (but functionally identical) formatting:
using( obj1 )
using( obj2 )
{
...
}
What is the difference between == and object.Equals?
Answer: For value types, == and Equals() usually compare two objects by value. For example:
int x = 10;
int y = 10;
Console.WriteLine( x == y );
Console.WriteLine( x.Equals(y) );
will display:
True
True
However things are more complex for reference types. Generally speaking, for reference types == is expected to perform an identity comparison, i.e. it will only return true if both references point to the same object. By contrast, Equals() is expected to perform a value comparison, i.e. it will return true if the references point to objects that are equivalent. For example:
StringBuilder s1 = new StringBuilder("skp");
StringBuilder s2 = new StringBuilder("skp");
Console.WriteLine( s1 == s2 );
Console.WriteLine( s1.Equals(s2) );
will display:
False
True
s1 and s2 are different objects (hence == returns false), but they are equivalent (hence Equals() returns true).
Unfortunately there are exceptions to these rules. The implementation of Equals() in System.Object (the one you'll inherit by default if you write a class) compares identity, i.e. it's the same as operator==. So Equals() only tests for equivalence if the class author overrides the method (and implements it correctly). Another exception is the string class - its operator== compares value rather than identity.
Bottom line: If we want to perform an identity comparison use the ReferenceEquals() method. If we want to perform a value comparison, use Equals() but be aware that it will only work if the type has overridden the default implementation. Avoid operator== with reference types (except perhaps strings), as it's simply too ambiguous.
How do we enforce const correctness in C#?
Answer: We can't - at least not in the same way you do in C++. C# (actually, the CLI) has no real concept of const correctness, For example, there's no way to specify that a method should not modify an argument passed in to it. And there's no way to specify that a method does not modify the object on which it is acting.
What are the new features in C# 2.0?
Answer: Support for all of the new framework features such as generics, anonymous methods, partial classes, iterators and static classes.
Delegate inference is a new feature of the C# compiler which makes delegate usage a little simpler. It allows us to write this:
Thread t = new Thread(ThreadFunc);
instead of this:
Thread t = new Thread( new ThreadStart(ThreadFunc) );
Another minor but welcome addition is the explicit global namespace, which fixes a hole in namespace usage in C# 1.x. We can prefix a type name with global:: to indicate that the type belongs to the global namespace, thus avoiding problems where the compiler infers the namespace and gets it wrong.
C# 2.0 includes some syntactic sugar for the new System.Nullable type. We can use T? as a synonym for System.Nullable, where T is a value type.
As suggested by the name, this allows values of the type to be 'null', or 'undefined'.
Are C# generics the same as C++ templates?
Answer: No, not really. There are some similarities, but there are also fundamental differences.
Who is a protected class-level variable available to?
Answer: It is available to any sub-class (a class inheriting this class).
Are private class-level variables inherited?
Answer: Yes, but they are not accessible. Although they are not visible or accessible via the class interface, they are inherited. |
Describe the accessibility modifier “protected internal”.
Answer: It is available to classes that are within the same assembly and derived from the specified base class.
What’s the top .NET class that everything is derived from?
Answer: System.Object.
What does the term immutable mean?
Answer: 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?
Answer: 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?
Answer: 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 we store multiple data types in System.Array?
Answer: No.
What’s the difference between the System.Array.CopyTo() and System.Array.Clone()?
Answer: 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 we sort the elements of the array in descending order?
Answer: By calling Sort() and then Reverse() methods.
What’s the .NET collection class that allows an element to be accessed using a unique key?
Answer: HashTable.
What class is underneath the SortedList class?
A sorted HashTable.
Will the finally block get executed if an exception has not occurred?
Answer: Yes.
What’s the C# syntax to catch any possible exception?
Answer: 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 {}.
Can multiple catch blocks be executed for a single try statement?
Answer: No. Once the proper catch block processed, control is transferred to the finally block (if there are any).
Explain the three services model commonly know as a three-tier application.
Answer: Presentation (UI), Business (logic and underlying code) and Data (from storage or other sources).
What is the syntax to inherit from a class in C#?
Answer: Place a colon and then the name of the base class.
Example: class MyNewClass : MyBaseClass
Can we prevent our class from being inherited by another class?
Answer: Yes. The keyword “sealed” will prevent the class from being inherited.
Can we allow a class to be inherited, but prevent the method from being over-ridden?
Answer: Yes. Just leave the class public and make the method sealed.
What’s an abstract class?
Answer: 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 we absolutely have to declare a class as abstract?
Answer:
§ When the class itself is inherited from an abstract class, but not all base abstract methods have been overridden.
§ When at least one of the methods in the class is abstract.
What is an interface class?
Answer: 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 we specify the accessibility modifier for methods inside the interface?
Answer: They all must be public, and are therefore public by default.
Can you inherit multiple interfaces?
Answer: Yes. .NET does support multiple interfaces.
What happens if we inherit multiple interfaces and they have conflicting method names?
Answer: It’s up to us to implement the method inside your own class, so implementation is left entirely up to us. 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 we’re okay.
What’s the difference between an interface and abstract class?
Answer: In an interface class, all methods are abstract - there is no implementation. In an abstract class some methods can be concrete. In an interface class, no accessibility modifiers are allowed. An abstract class may have accessibility modifiers.
What is the difference between a Struct and a Class?
Answer: Structs are value-type variables and are thus saved on the stack, additional overhead but faster retrieval. Another difference is that structs cannot inherit.
What’s the implicit name of the parameter that gets passed into the set method/property of a class?
Answer: Value. The data type of the value parameter is defined by whatever data type the property is declared as.
What does the keyword “virtual” declare for a method or property?
Answer: The method or property can be overridden.
How is method overriding different from method overloading?
Answer: When overriding a method, you change the behavior of the method for the derived class. Overloading a method simply involves having another method with the same name within the class.
Can we declare an override method to be static if the original method is not static?
Answer: No. The signature of the virtual method must remain the same. (Note: Only the keyword virtual is changed to keyword override)
What are the different ways a method can be overloaded?
Answer: Different parameter data types, different number of parameters, different order of parameters.
If a base class has a number of overloaded constructors, and an inheriting class has a number of overloaded constructors; can we enforce a call from an inherited constructor to a specific base constructor?
Answer: Yes, just place a colon, and then keyword base (parameter list to invoke the appropriate constructor) in the overloaded constructor definition inside the inherited class.
What’s a delegate?
Answer: A delegate object encapsulates a reference to a method.
What’s a multicast delegate?
Answer: A delegate that has multiple handlers assigned to it. Each assigned handler (method) is called.
What’s the difference between // comments, /* */ comments and /// comments?
Answer: Single-line comments, multi-line comments, and XML documentation comments.
How do we generate documentation from the C# file commented properly with a command-line compiler?
Answer: Compile it with the /doc switch.
What debugging tools come with the .NET SDK?
Answer:
1. CorDBG – command-line debugger. To use CorDbg, you must compile the original C# file using the /debug switch.
2. DbgCLR – graphic debugger. Visual Studio .NET uses the DbgCLR.
What does assert() method do?
Answer: In debug compilation, assert takes in a Boolean condition as a parameter, and shows the error dialog if the condition is false. The program proceeds without any interruption if the condition is true.
What’s the difference between the Debug class and Trace class?
Answer: Documentation looks the same. Use Debug class for debug builds, use Trace class for both debug and release builds.
Why are there five tracing levels in System.Diagnostics.TraceSwitcher?
Answer: The tracing dumps can be quite verbose. For applications that are constantly running you run the risk of overloading the machine and the hard drive. Five levels range from None to Verbose, allowing you to fine-tune the tracing activities.
Where is the output of TextWriterTraceListener redirected?
Answer: To the Console or a text file depending on the parameter passed to the constructor.
How do you debug an ASP.NET Web application?
Answer: Attach the aspnet_wp.exe process to the DbgClr debugger.
What are three test cases you should go through in unit testing?
Answer:
1. Positive test cases (correct data, correct output).
2. Negative test cases (broken or missing data, proper handling).
3. Exception test cases (exceptions are thrown and caught properly).
Can we change the value of a variable while debugging a C# application?
Answer: Yes. If we are debugging via Visual Studio.NET, just go to Immediate window.
What is the role of the DataReader class in ADO.NET connections?
Answer: It returns a read-only, forward-only rowset from the data source. A DataReader provides fast access when a forward-only sequential read is needed.
What are advantages and disadvantages of Microsoft-provided data provider classes in ADO.NET?
Answer: SQLServer.NET data provider is high-speed and robust, but requires SQL Server license purchased from Microsoft. OLE-DB.NET is universal for accessing other sources, like Oracle, DB2, Microsoft Access and Informix. OLE-DB.NET is a .NET layer on top of the OLE layer, so it’s not as fastest and efficient as SqlServer.NET.
Explain ACID rule of thumb for transactions.
Answer: A transaction must be:
1. Atomic - it is one unit of work and does not dependent on previous and following transactions.
2. Consistent - data is either committed or roll back, no “in-between” case where something has been updated and something hasn’t.
3. Isolated - no transaction sees the intermediate results of the current transaction).
4. Durable - the values persist if the data had been committed even if the system crashes right after.
What connections does Microsoft SQL Server support?
Answer: Windows Authentication (via Active Directory) and SQL Server authentication (via Microsoft SQL Server username and password).
Between Windows Authentication and SQL Server Authentication, which one is trusted and which one is untrusted?
Answer: Windows Authentication is trusted because the username and password are checked with the Active Directory, the SQL Server authentication is untrusted, since SQL Server is the only verifier participating in the transaction.
What does the Initial Catalog parameter define in the connection string?
Answer: The database name to connect to.
What does the Dispose method do with the connection object?
Answer: Deletes it from the memory.
What is a pre-requisite for connection pooling?
Answer: Multiple processes must agree that they will share the same connection, where every parameter is the same, including the security settings. The connection string must be identical.
How is the DLL Hell problem solved in .NET?
Answer: 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.
What are the ways to deploy an assembly?
Answer: An MSI installer, a CAB archive, and XCOPY command.
What is a satellite assembly?
Answer: When we write a multilingual or multi-cultural application in .NET, and want to distribute the core application separately from the localized modules, the localized assemblies that modify the core application are called satellite assemblies.
What namespaces are necessary to create a localized application?
Answer: System.Globalization and System.Resources.
What is the smallest unit of execution in .NET?
Answer: an Assembly.
When should we call the garbage collector in .NET?
Answer: As a good rule, we should not call the garbage collector. However, we could call the garbage collector when we are done using a large object (or set of objects) to force the garbage collector to dispose of those very large objects from memory. However, this is usually not a good practice.
How do you convert a value-type to a reference-type?
Answer: Use Boxing.
What happens in memory when we Box and Unbox a value-type?
Answer: Boxing converts a value-type to a reference-type, thus storing the object on the heap. Unboxing converts a reference-type to a value-type, thus storing the value on the stack.
Describe the role of inetinfo.exe, aspnet_isapi.dll andaspnet_wp.exe in the page loading process.
Answer: inetinfo.exe is theMicrosoft IIS server running, handling ASP.NET requests among other things.When an ASP.NET request is received (usually a file with .aspx extension), the ISAPI filter aspnet_isapi.dll takes care of it by passing the request tothe actual worker process aspnet_wp.exe.
What’s the difference between Response.Write() andResponse.Output.Write()?
Answer: Response.Output.Write() allows you to write formatted output.
What methods are fired during the page load?
Answer:
Init() - when the page is instantiated
Load() - when the page is loaded into server memory
PreRender() - the brief moment before the page is displayed to the user as HTML
Unload() - when page finishes loading.
When during the page processing cycle is ViewState available?
Answer: After the Init() and before the Page_Load(), or OnLoad() for a control.
What namespace does the Web page belong in the .NET Framework class hierarchy?
Answer: System.Web.UI.Page
Where do we store the information about the user’s locale?
Answer: System.Web.UI.Page.Culture
What’s the difference between Codebehind="MyCode.aspx.cs" andSrc="MyCode.aspx.cs"?
Answer: CodeBehind is relevant to Visual Studio.NET only.
What’s a bubbled event?
Answer: When we have a complex control, like DataGrid, writing an event processing routine for each object (cell, button, row, etc.) is quite tedious. The controls can bubble up their eventhandlers, allowing the main DataGrid event handler to take care of its constituents.
Suppose we want a certain ASP.NET function executed on MouseOver for a certain button. Where do we add an event handler?
Answer: Add an OnMouseOver attribute to the button. Example: btnSubmit.Attributes.Add("onmouseover","someClientCodeHere();");
What data types do the RangeValidator control support?
Answer: Integer, String, and Date.
Explain the differences between Server-side and Client-side code?
Answer: Server-side code executes on the server. Client-side code executes in the client's browser.
What type of code (server or client) is found in a Code-Behind class?
Answer: The answer is server-side code since code-behind is executed on the server. However, during the code-behind's execution on the server, it can render client-side code such as JavaScript to be processed in the clients browser. But just to be clear, code-behind executes on the server, thus making it server-side code.
Should user input data validation occur server-side or client-side? Why?
Answer: All user input data validation should occur on the server at a minimum. Additionally, client-side validation can be performed where deemed appropriate and feasable to provide a richer, more responsive experience for the user.
What is the difference between Server.Transfer and Response.Redirect? Why would we choose one over the other?
Answer: Server.Transfer transfers page processing from one page directly to the next page without making a round-trip back to the client's browser. This provides a faster response with a little less overhead on the server. Server.Transfer does not update the clients url history list or current url. Response.Redirect is used to redirect the user's browser to another page or site. This performas a trip back to the client where the client's browser is redirected to the new page. The user's browser history list is updated to reflect the new address.
Explain the difference between an ADO.NET Dataset and an ADO Recordset.
Answer: Valid answers are:
· A DataSet can represent an entire relational database in memory, complete with tables, relations, and views.
· A DataSet is designed to work without any continuing connection to the original data source.
· Data in a DataSet is bulk-loaded, rather than being loaded on demand.
· There's no concept of cursor types in a DataSet.
· DataSets have no current record pointer You can use For Each loops to move through the data.
· You can store many edits in a DataSet, and write them to the original data source in a single operation.
· Though the DataSet is universal, other objects in ADO.NET come in different versions for different data sources.
What is the Global.asax used for?
Answer:
The Global.asax (including the Global.asax.cs file) is used to implement application and session level events.
What are the Application_Start and Session_Start subroutines used for?
Answer: This is where you can set the specific variables for the Application and Session objects.
Describe the difference between inline and code behind.
Answer: Inline code written along side the html in a page. Code-behind is code written in a separate file and referenced by the .aspx page.
Explain what a diffgram is, and a good use for one?
Answer: The DiffGram is one of the two XML formats that you can use to render DataSet object contents to XML. A good use is reading database data to an XML file to be sent to a Web Service.
Whats MSIL, and why should my developers need an appreciation of it if at all?
Answer: MSIL is the Microsoft Intermediate Language. All .NET compatible languages will get converted to MSIL. MSIL also allows the .NET Framework to JIT compile the assembly on the installed computer.
Which method do we invoke on the DataAdapter control to load your generated dataset with data?
Answer: The Fill() method.
Can we edit data in the Repeater control?
Answer: No, it just reads the information from its data source.
Which template must you provide, in order to display data in a Repeater control?
Answer: ItemTemplate.
How can we provide an alternating color scheme in a Repeater control?
Answer: Use the AlternatingItemTemplate.
What property must we set, and what method must we call in our code, in order to bind the data from a data source to the Repeater control?
Answer: We must set the DataSource property and call the DataBind method.
What base class do all Web Forms inherit from?
Answer: The Page class.
Name two properties common in every validation control?
Answer: ControlToValidate property and Text property.
Which property on a Combo Box do we set with a column name, prior to setting the DataSource, to display data in the combo box?
Answer: DataTextField property.
Which control would you we if you needed to make sure the values in two different controls matched?
Answer: CompareValidator control.
How many classes can a single .NET DLL contain?
Answer: It can contain many classes.
What is the transport protocol we use to call a Web service?
Answer: SOAP (Simple Object Access Protocol) is the preferred protocol.
What does WSDL stand for?
Answer: Web Services Description Language.
What is ViewState?
Answer: ViewState allows the state of objects (serializable) to be stored in a hidden field on the page. ViewState is transported to the client and back to the server, and is not stored on the server or any other external source. ViewState is used the retain the state of server-side objects between postabacks.
What is the lifespan for items stored in ViewState?
Answer: Item stored in ViewState exist for the life of the current page. This includes postbacks (to the same page).
What does the "EnableViewState" property do? Why would we want it on or off?
Answer: It allows the page to save the users input on a form across postbacks. It saves the server-side values for a given control into ViewState, which is stored as a hidden value on the page before sending the page to the clients browser. When the page is posted back to the server the server control is recreated with the state stored in viewstate.
What are the different types of Session state management options available with ASP.NET?
Answer: ASP.NET provides In-Process and Out-of-Process state management. In-Process stores the session in memory on the web server. This requires the a "sticky-server" (or no load-balancing) so that the user is always reconnected to the same web server. Out-of-Process Session state management stores data in an external data source. The external data source may be either a SQL Server or a State Server service. Out-of-Process state management requires that all objects stored in session are serializable.
What Are the Goals of the Compact Framework?
Answer: The goals of the Compact Framework (and Smart Device Projects) are fourfold:
? To provide a portable (and small) subset of the Windows .NET Framework targeting multiple platforms. This includes the creation of a runtime engine, class libraries, and compilers for VB and C# that together are referred to as the .NET Compact Framework. This framework is not a simple port of the desktop version, but a complete rewrite designed to execute managed code on multiple CPU architectures and operating systems through an abstraction layer known as the Platform Adaption Layer (PAL). It is important to note that the Compact Framework was also designed to be a subset of the desktop version of the Framework. As a result, roughly 25% of the desktop types are represented in the Compact Framework.
?Leverage VS .NET. Since VS .NET already provides a high productivity development environment, it is only natural that this environment should be utilized in developing mobile applications as well. To that end, the Smart Device Projects for VS .NET 2003 provide the project templates, emulator, debugger, and device integration to use the same IDE for desktop as for mobile development.
? True Emulation. One of the requirements for developing robust (i.e., well-debugged) mobile applications is that they run as expected when installed on the device. To that end VS.NET includes emulators for Pocket PC and Windows CE that run exactly the same execution engine and class libraries as those installed on the device. In addition, the emulator supports localized packages for developing global applications. In this way, developers can be assured that the code they write and test with the emulator will execute correctly when deployed to the device.
?Enable Web Services on Devices. Since XML Web Services are by definition device independent, they can be used from a variety of devices. By building support for consuming web services directly into the Compact Framework, developers can easily call web services.
On Which Platforms Does It Run?
Answer: Since 1992 Microsoft has produced a series of platforms (9 if our count is correct) built on the Windows CE operating system. A platform includes a specific set of hardware coupled with a version of Windows CE and associated software that makes it easier for developers and device manufacturers to target their solutions. The Compact Framework supports the Pocket PC 2000, 2002, and embedded Windows CE .NET 4.1 platforms. Although not officially supported, Compact Framework code also runs on Pocket PC Phone Edition devices that are a superset of Pocket PC 2002. Also not supported are smartphones such as the SPV from Orange.
Because the Compact Framework is a managed environment, each device that executes applications written using the Compact Framework must have the framework installed. As of this writing, there were no devices shipping that included the Compact Framework as a standard component in RAM or in ROM. However, look for future devices running Windows CE .NET to include the runtime.
What About ASP.NET Mobile Controls (aka the Mobile Internet Toolkit)?
Answer: Many developers new to developing for mobility are at first confused by the differences between the Compact Framework and ASP.NET Mobile Controls. In a nutshell here are the primary differences.
? The ASP.NET Mobile Controls are a server side technology whereas the Compact Framework is a client side technology. This means that code written using mobile controls must execute on a server, and not directly on the device, by producing markup language that is interpreted by the device using a browser or parser. Code written for the Compact Framework executes directly on the device using just-in-time (JIT) compilation and native execution.
? The ASP.NET Mobile Controls are based on ASP.NET and use the ASP.NET HTTP runtime to handle and process requests via a set of ASP.NET server controls specially designed for small form factor devices. This means that mobile controls require an ASP.NET web server (IIS 5.0 or 6.0). The device issues requests that are processed on the web server by the controls producing markup language.
?Both ASP.NET Mobile Controls and the Compact Framework are based on the desktop Framework and VS .NET. In the case of mobile controls, developers use VS .NET to write ASP.NET code using the ASP.NET server controls. The server side code is JIT compiled and executed on the web server by the common language runtime. In the case of the Compact Framework the code is written using SDP and subsequently downloaded to the device for JITting and execution using a compact version of the common language runtime.
? The ASP.NET Mobile Controls are more flexible in that they can dynamically produce various markup languages depending on the requesting device they dynamically detect, including WML, cHTML, HTML, and XHTML (in Visual Studio .NET 2003 and the Framework v1.1). This means that mobile controls can support a broader range of devices (over 200 at last count) including wireless web phones, Pocket PCs, and virtually any device that supports HTTP and HTML. The ASP.NET Mobile Controls also include the ability to add device specific customizations so that as new devices come online their feature set can be identified.
? Since code written for the Compact Framework is downloaded to the device, the Compact Framework supports connected, occasionally connected, and disconnected scenarios and supports local data storage using XML or SQL Server 2000 Windows CE Edition. ASP.NET Mobile Controls only support the former since an HTTP connection is required to request an ASP.NET page that uses the mobile controls. Basically, this means that mobile controls are targeted for building web sites for a broad variety of connected devices and at the same time not having to rewrite the vast majority of code to deal with differences between those devices.
As a result we can (and in our estimation should) consider architecting and building your applications using the Compact Framework and SDP when the following are true.
? You are developing code that will execute on the device, as opposed to applications developed with the ASP.NET Mobile Controls
? Your applications must run in disconnected, connected, or occasionally connected modes
? You are targeting the Pocket PC 2000, 2002 or embedded Windows CE .NET platforms
What's Missing in the Compact Framework?
Answer: In order to accommodate the restricted resources on smart devices the Compact Framework was designed as a subset of the desktop libraries and in fact includes just over 1,700 types, or roughly 25% of the desktop framework. As a result, developers familiar with the desktop Framework should not expect all the functionality they are accustomed to. The most important omissions are listed here:
? ASP.NET. Because the Compact Framework is designed to support applications that execute on the device, it does not include any support for building web pages hosted on a web server running on the device.
? COM Interop. Since the Windows CE operating system and the embedded Visual C++ (eVC) tool support creating COM components and ActiveX controls, it would be nice if the Compact Framework supported the same COM Interop functionality (complete with COM callable wrappers and interop assemblies) as does the desktop Framework. Unfortunately, COM Interop did not make it into the initial release of the Compact Framework. However, it is possible to create a DLL wrapper for a COM component using eVC++ and then call the wrapper using the Platform Invoke (PInvoke) feature of the Compact Framework, which allows native APIs to be called.
? OleDb Access. The Compact Framework omits the System.Data.OleDb namespace and so does not support the ability to make calls directly to a database using the OleDb .NET Data Provider.
? Generic Serialization. The desktop Framework supports binary serialization of any object through the use of the Serializable attribute, the ISerializable interface, and the XmlSerializer class in the System.Xml.Serialization namespace. This functionality is not supported in the Compact Framework. However, the Compact Framework does support serializing objects to XML for use in XML Web Services and serializing DataSet objects to XML.
? Asynchronous Delegates. Delegates in both the desktop Framework and Compact Framework can be thought of as object-oriented function pointers. They are used to encapsulate the signature and address of a method to invoke at runtime. While delegates can be called synchronously, they cannot be invoked asynchronously and passed a callback method in the Compact Framework. However, it should be noted that asynchronous operations are supported for some of the networking functionality found in the System.Net namespace and when calling XML Web Services. In other cases, direct manipulation of threads or the use of a thread pool is required.
? .NET Remoting. In the desktop Framework, it is possible to create applications that communicate with each other across application domains using classes in the System.Runtime.Remoting namespace. This technique allows for data and objects serialized to SOAP or a binary format to be transmitted using TCP or HTTP. This functionality is not supported (in part because Generic Serialization is not supported) in the Compact Framework where instead XML Web Services and IrDA can be used.
? Reflection Emit. Although the Compact Framework does support runtime type inspection using the System.Reflection namespace, it does not support the ability to emit dynamically created MSIL into an assembly for execution.
? Printing. Although the Compact Framework does support graphics and drawing, it does not support printing through the System.Drawing.Printing namespace.
? XPath/XSLT. Support for XML is included in the Compact Framework and allows developers to read and write XML documents using the XmlDocument, XmlReader, and XmlWriter classes. However, it does not support executing XPath queries or performing XSL transformations.
? Server-side Programming Models. As you would expect, the Compact Framework also does not support the server-side programming models including System.EnterpriseServices (COM+), System.Management (WMI), and System.Messaging (MSMQ).
? Multi-module Assemblies. The desktop Framework supports the ability to deploy an assembly as a collection of files. This is useful for creating assemblies authored with multiple languages. This feature is not supported in the Compact Framework where a single file (.exe or .dll) represents the entire assembly.
However, the Compact Framework does support two additional namespaces to support features particular to smart devices (see Table 1).
In addition, support for the IrDA protocol has been included in the Compact Framework and exposed in the six classes found in the System.Net.Sockets and the System.Net namespaces.
What Do Developers Need to Learn to Use the Compact Framework Effectively?
Answer: Although VB 6.0 and embedded VB (eVB) developers will feel fairly comfortable with the VB syntax used in SDP, the object-oriented nature of the Compact Framework means that developers need to have a firm grounding in OO concepts in order to maximize their productivity.
For example, the class libraries in the Compact Framework make extensive use of both implementation and interface inheritance. Developers familiar with these concepts can not only more easily understand the framework, but can write polymorphic code using the framework that is more maintainable and flexible than the component based development typically done in eVB. In the long run, using OO in their own designs allows developers to write less code and make the code that they do write more reusable. Therefore, to take maximum advantage of OO, however, a development organization should also get up to speed on the use of design patterns.
Answer: Use the String.Compare function. Its third parameter is a boolean which specifies whether case should be ignored or not.
"skp" == "Skp" // false
System.String.Compare( "skp", "Skp", true ) // true
Does C# support a variable number of arguments?
Answer: Yes, using the params keyword. The arguments are specified as a list of arguments of a specific type, e.g. int. For ultimate flexibility, the type can be object. The standard example of a method which uses this approach is System.Console.WriteLine().
How can we process command-line arguments?
Answer: Like this:
using System;
class CApp
{
public static void Main( string[] args )
{
Console.WriteLine( "You passed the following arguments:" );
foreach( string arg in args )
Console.WriteLine( arg );
}
}
Does C# do array bounds checking?
Answer: Yes. An IndexOutOfRange exception is used to signal an error.
How can we make sure our C# classes will interoperate with other .NET languages?
Answer: Make sure our C# code conforms to the Common Language Subset (CLS). To help with this, add the [assembly:CLSCompliant(true)] global attribute to your C# source files. The compiler will emit an error if you use a C# feature which is not CLS-compliant.
How do we use the 'using' keyword with multiple objects?
Answer: We can nest using statements, like this:
using( obj1 )
{
using( obj2 )
{
...
}
}
However consider using this more aesthetically pleasing (but functionally identical) formatting:
using( obj1 )
using( obj2 )
{
...
}
What is the difference between == and object.Equals?
Answer: For value types, == and Equals() usually compare two objects by value. For example:
int x = 10;
int y = 10;
Console.WriteLine( x == y );
Console.WriteLine( x.Equals(y) );
will display:
True
True
However things are more complex for reference types. Generally speaking, for reference types == is expected to perform an identity comparison, i.e. it will only return true if both references point to the same object. By contrast, Equals() is expected to perform a value comparison, i.e. it will return true if the references point to objects that are equivalent. For example:
StringBuilder s1 = new StringBuilder("skp");
StringBuilder s2 = new StringBuilder("skp");
Console.WriteLine( s1 == s2 );
Console.WriteLine( s1.Equals(s2) );
will display:
False
True
s1 and s2 are different objects (hence == returns false), but they are equivalent (hence Equals() returns true).
Unfortunately there are exceptions to these rules. The implementation of Equals() in System.Object (the one you'll inherit by default if you write a class) compares identity, i.e. it's the same as operator==. So Equals() only tests for equivalence if the class author overrides the method (and implements it correctly). Another exception is the string class - its operator== compares value rather than identity.
Bottom line: If we want to perform an identity comparison use the ReferenceEquals() method. If we want to perform a value comparison, use Equals() but be aware that it will only work if the type has overridden the default implementation. Avoid operator== with reference types (except perhaps strings), as it's simply too ambiguous.
How do we enforce const correctness in C#?
Answer: We can't - at least not in the same way you do in C++. C# (actually, the CLI) has no real concept of const correctness, For example, there's no way to specify that a method should not modify an argument passed in to it. And there's no way to specify that a method does not modify the object on which it is acting.
What are the new features in C# 2.0?
Answer: Support for all of the new framework features such as generics, anonymous methods, partial classes, iterators and static classes.
Delegate inference is a new feature of the C# compiler which makes delegate usage a little simpler. It allows us to write this:
Thread t = new Thread(ThreadFunc);
instead of this:
Thread t = new Thread( new ThreadStart(ThreadFunc) );
Another minor but welcome addition is the explicit global namespace, which fixes a hole in namespace usage in C# 1.x. We can prefix a type name with global:: to indicate that the type belongs to the global namespace, thus avoiding problems where the compiler infers the namespace and gets it wrong.
C# 2.0 includes some syntactic sugar for the new System.Nullable type. We can use T? as a synonym for System.Nullable
As suggested by the name, this allows values of the type to be 'null', or 'undefined'.
Answer: No, not really. There are some similarities, but there are also fundamental differences.
Who is a protected class-level variable available to?
Answer: It is available to any sub-class (a class inheriting this class).
Are private class-level variables inherited?
Answer: Yes, but they are not accessible. Although they are not visible or accessible via the class interface, they are inherited. |
Describe the accessibility modifier “protected internal”.
Answer: It is available to classes that are within the same assembly and derived from the specified base class.
What’s the top .NET class that everything is derived from?
Answer: System.Object.
What does the term immutable mean?
Answer: 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?
Answer: 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?
Answer: 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 we store multiple data types in System.Array?
Answer: No.
What’s the difference between the System.Array.CopyTo() and System.Array.Clone()?
Answer: 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 we sort the elements of the array in descending order?
Answer: By calling Sort() and then Reverse() methods.
What’s the .NET collection class that allows an element to be accessed using a unique key?
Answer: HashTable.
What class is underneath the SortedList class?
A sorted HashTable.
Will the finally block get executed if an exception has not occurred?
Answer: Yes.
What’s the C# syntax to catch any possible exception?
Answer: 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 {}.
Can multiple catch blocks be executed for a single try statement?
Answer: No. Once the proper catch block processed, control is transferred to the finally block (if there are any).
Explain the three services model commonly know as a three-tier application.
Answer: Presentation (UI), Business (logic and underlying code) and Data (from storage or other sources).
What is the syntax to inherit from a class in C#?
Answer: Place a colon and then the name of the base class.
Example: class MyNewClass : MyBaseClass
Can we prevent our class from being inherited by another class?
Answer: Yes. The keyword “sealed” will prevent the class from being inherited.
Can we allow a class to be inherited, but prevent the method from being over-ridden?
Answer: Yes. Just leave the class public and make the method sealed.
What’s an abstract class?
Answer: 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 we absolutely have to declare a class as abstract?
Answer:
§ When the class itself is inherited from an abstract class, but not all base abstract methods have been overridden.
§ When at least one of the methods in the class is abstract.
What is an interface class?
Answer: 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 we specify the accessibility modifier for methods inside the interface?
Answer: They all must be public, and are therefore public by default.
Can you inherit multiple interfaces?
Answer: Yes. .NET does support multiple interfaces.
What happens if we inherit multiple interfaces and they have conflicting method names?
Answer: It’s up to us to implement the method inside your own class, so implementation is left entirely up to us. 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 we’re okay.
What’s the difference between an interface and abstract class?
Answer: In an interface class, all methods are abstract - there is no implementation. In an abstract class some methods can be concrete. In an interface class, no accessibility modifiers are allowed. An abstract class may have accessibility modifiers.
What is the difference between a Struct and a Class?
Answer: Structs are value-type variables and are thus saved on the stack, additional overhead but faster retrieval. Another difference is that structs cannot inherit.
What’s the implicit name of the parameter that gets passed into the set method/property of a class?
Answer: Value. The data type of the value parameter is defined by whatever data type the property is declared as.
What does the keyword “virtual” declare for a method or property?
Answer: The method or property can be overridden.
How is method overriding different from method overloading?
Answer: When overriding a method, you change the behavior of the method for the derived class. Overloading a method simply involves having another method with the same name within the class.
Can we declare an override method to be static if the original method is not static?
Answer: No. The signature of the virtual method must remain the same. (Note: Only the keyword virtual is changed to keyword override)
What are the different ways a method can be overloaded?
Answer: Different parameter data types, different number of parameters, different order of parameters.
If a base class has a number of overloaded constructors, and an inheriting class has a number of overloaded constructors; can we enforce a call from an inherited constructor to a specific base constructor?
Answer: Yes, just place a colon, and then keyword base (parameter list to invoke the appropriate constructor) in the overloaded constructor definition inside the inherited class.
What’s a delegate?
Answer: A delegate object encapsulates a reference to a method.
What’s a multicast delegate?
Answer: A delegate that has multiple handlers assigned to it. Each assigned handler (method) is called.
What’s the difference between // comments, /* */ comments and /// comments?
Answer: Single-line comments, multi-line comments, and XML documentation comments.
How do we generate documentation from the C# file commented properly with a command-line compiler?
Answer: Compile it with the /doc switch.
What debugging tools come with the .NET SDK?
Answer:
1. CorDBG – command-line debugger. To use CorDbg, you must compile the original C# file using the /debug switch.
2. DbgCLR – graphic debugger. Visual Studio .NET uses the DbgCLR.
What does assert() method do?
Answer: In debug compilation, assert takes in a Boolean condition as a parameter, and shows the error dialog if the condition is false. The program proceeds without any interruption if the condition is true.
What’s the difference between the Debug class and Trace class?
Answer: Documentation looks the same. Use Debug class for debug builds, use Trace class for both debug and release builds.
Why are there five tracing levels in System.Diagnostics.TraceSwitcher?
Answer: The tracing dumps can be quite verbose. For applications that are constantly running you run the risk of overloading the machine and the hard drive. Five levels range from None to Verbose, allowing you to fine-tune the tracing activities.
Where is the output of TextWriterTraceListener redirected?
Answer: To the Console or a text file depending on the parameter passed to the constructor.
How do you debug an ASP.NET Web application?
Answer: Attach the aspnet_wp.exe process to the DbgClr debugger.
What are three test cases you should go through in unit testing?
Answer:
1. Positive test cases (correct data, correct output).
2. Negative test cases (broken or missing data, proper handling).
3. Exception test cases (exceptions are thrown and caught properly).
Can we change the value of a variable while debugging a C# application?
Answer: Yes. If we are debugging via Visual Studio.NET, just go to Immediate window.
What is the role of the DataReader class in ADO.NET connections?
Answer: It returns a read-only, forward-only rowset from the data source. A DataReader provides fast access when a forward-only sequential read is needed.
What are advantages and disadvantages of Microsoft-provided data provider classes in ADO.NET?
Answer: SQLServer.NET data provider is high-speed and robust, but requires SQL Server license purchased from Microsoft. OLE-DB.NET is universal for accessing other sources, like Oracle, DB2, Microsoft Access and Informix. OLE-DB.NET is a .NET layer on top of the OLE layer, so it’s not as fastest and efficient as SqlServer.NET.
Explain ACID rule of thumb for transactions.
Answer: A transaction must be:
1. Atomic - it is one unit of work and does not dependent on previous and following transactions.
2. Consistent - data is either committed or roll back, no “in-between” case where something has been updated and something hasn’t.
3. Isolated - no transaction sees the intermediate results of the current transaction).
4. Durable - the values persist if the data had been committed even if the system crashes right after.
What connections does Microsoft SQL Server support?
Answer: Windows Authentication (via Active Directory) and SQL Server authentication (via Microsoft SQL Server username and password).
Between Windows Authentication and SQL Server Authentication, which one is trusted and which one is untrusted?
Answer: Windows Authentication is trusted because the username and password are checked with the Active Directory, the SQL Server authentication is untrusted, since SQL Server is the only verifier participating in the transaction.
What does the Initial Catalog parameter define in the connection string?
Answer: The database name to connect to.
What does the Dispose method do with the connection object?
Answer: Deletes it from the memory.
What is a pre-requisite for connection pooling?
Answer: Multiple processes must agree that they will share the same connection, where every parameter is the same, including the security settings. The connection string must be identical.
How is the DLL Hell problem solved in .NET?
Answer: 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.
What are the ways to deploy an assembly?
Answer: An MSI installer, a CAB archive, and XCOPY command.
What is a satellite assembly?
Answer: When we write a multilingual or multi-cultural application in .NET, and want to distribute the core application separately from the localized modules, the localized assemblies that modify the core application are called satellite assemblies.
What namespaces are necessary to create a localized application?
Answer: System.Globalization and System.Resources.
What is the smallest unit of execution in .NET?
Answer: an Assembly.
When should we call the garbage collector in .NET?
Answer: As a good rule, we should not call the garbage collector. However, we could call the garbage collector when we are done using a large object (or set of objects) to force the garbage collector to dispose of those very large objects from memory. However, this is usually not a good practice.
How do you convert a value-type to a reference-type?
Answer: Use Boxing.
What happens in memory when we Box and Unbox a value-type?
Answer: Boxing converts a value-type to a reference-type, thus storing the object on the heap. Unboxing converts a reference-type to a value-type, thus storing the value on the stack.
Describe the role of inetinfo.exe, aspnet_isapi.dll andaspnet_wp.exe in the page loading process.
Answer: inetinfo.exe is theMicrosoft IIS server running, handling ASP.NET requests among other things.When an ASP.NET request is received (usually a file with .aspx extension), the ISAPI filter aspnet_isapi.dll takes care of it by passing the request tothe actual worker process aspnet_wp.exe.
What’s the difference between Response.Write() andResponse.Output.Write()?
Answer: Response.Output.Write() allows you to write formatted output.
What methods are fired during the page load?
Answer:
Init() - when the page is instantiated
Load() - when the page is loaded into server memory
PreRender() - the brief moment before the page is displayed to the user as HTML
Unload() - when page finishes loading.
When during the page processing cycle is ViewState available?
Answer: After the Init() and before the Page_Load(), or OnLoad() for a control.
What namespace does the Web page belong in the .NET Framework class hierarchy?
Answer: System.Web.UI.Page
Where do we store the information about the user’s locale?
Answer: System.Web.UI.Page.Culture
What’s the difference between Codebehind="MyCode.aspx.cs" andSrc="MyCode.aspx.cs"?
Answer: CodeBehind is relevant to Visual Studio.NET only.
What’s a bubbled event?
Answer: When we have a complex control, like DataGrid, writing an event processing routine for each object (cell, button, row, etc.) is quite tedious. The controls can bubble up their eventhandlers, allowing the main DataGrid event handler to take care of its constituents.
Suppose we want a certain ASP.NET function executed on MouseOver for a certain button. Where do we add an event handler?
Answer: Add an OnMouseOver attribute to the button. Example: btnSubmit.Attributes.Add("onmouseover","someClientCodeHere();");
What data types do the RangeValidator control support?
Answer: Integer, String, and Date.
Explain the differences between Server-side and Client-side code?
Answer: Server-side code executes on the server. Client-side code executes in the client's browser.
What type of code (server or client) is found in a Code-Behind class?
Answer: The answer is server-side code since code-behind is executed on the server. However, during the code-behind's execution on the server, it can render client-side code such as JavaScript to be processed in the clients browser. But just to be clear, code-behind executes on the server, thus making it server-side code.
Should user input data validation occur server-side or client-side? Why?
Answer: All user input data validation should occur on the server at a minimum. Additionally, client-side validation can be performed where deemed appropriate and feasable to provide a richer, more responsive experience for the user.
What is the difference between Server.Transfer and Response.Redirect? Why would we choose one over the other?
Answer: Server.Transfer transfers page processing from one page directly to the next page without making a round-trip back to the client's browser. This provides a faster response with a little less overhead on the server. Server.Transfer does not update the clients url history list or current url. Response.Redirect is used to redirect the user's browser to another page or site. This performas a trip back to the client where the client's browser is redirected to the new page. The user's browser history list is updated to reflect the new address.
Explain the difference between an ADO.NET Dataset and an ADO Recordset.
Answer: Valid answers are:
· A DataSet can represent an entire relational database in memory, complete with tables, relations, and views.
· A DataSet is designed to work without any continuing connection to the original data source.
· Data in a DataSet is bulk-loaded, rather than being loaded on demand.
· There's no concept of cursor types in a DataSet.
· DataSets have no current record pointer You can use For Each loops to move through the data.
· You can store many edits in a DataSet, and write them to the original data source in a single operation.
· Though the DataSet is universal, other objects in ADO.NET come in different versions for different data sources.
What is the Global.asax used for?
Answer:
The Global.asax (including the Global.asax.cs file) is used to implement application and session level events.
What are the Application_Start and Session_Start subroutines used for?
Answer: This is where you can set the specific variables for the Application and Session objects.
Describe the difference between inline and code behind.
Answer: Inline code written along side the html in a page. Code-behind is code written in a separate file and referenced by the .aspx page.
Explain what a diffgram is, and a good use for one?
Answer: The DiffGram is one of the two XML formats that you can use to render DataSet object contents to XML. A good use is reading database data to an XML file to be sent to a Web Service.
Whats MSIL, and why should my developers need an appreciation of it if at all?
Answer: MSIL is the Microsoft Intermediate Language. All .NET compatible languages will get converted to MSIL. MSIL also allows the .NET Framework to JIT compile the assembly on the installed computer.
Which method do we invoke on the DataAdapter control to load your generated dataset with data?
Answer: The Fill() method.
Can we edit data in the Repeater control?
Answer: No, it just reads the information from its data source.
Which template must you provide, in order to display data in a Repeater control?
Answer: ItemTemplate.
How can we provide an alternating color scheme in a Repeater control?
Answer: Use the AlternatingItemTemplate.
What property must we set, and what method must we call in our code, in order to bind the data from a data source to the Repeater control?
Answer: We must set the DataSource property and call the DataBind method.
What base class do all Web Forms inherit from?
Answer: The Page class.
Name two properties common in every validation control?
Answer: ControlToValidate property and Text property.
Which property on a Combo Box do we set with a column name, prior to setting the DataSource, to display data in the combo box?
Answer: DataTextField property.
Which control would you we if you needed to make sure the values in two different controls matched?
Answer: CompareValidator control.
How many classes can a single .NET DLL contain?
Answer: It can contain many classes.
What is the transport protocol we use to call a Web service?
Answer: SOAP (Simple Object Access Protocol) is the preferred protocol.
What does WSDL stand for?
Answer: Web Services Description Language.
What is ViewState?
Answer: ViewState allows the state of objects (serializable) to be stored in a hidden field on the page. ViewState is transported to the client and back to the server, and is not stored on the server or any other external source. ViewState is used the retain the state of server-side objects between postabacks.
What is the lifespan for items stored in ViewState?
Answer: Item stored in ViewState exist for the life of the current page. This includes postbacks (to the same page).
What does the "EnableViewState" property do? Why would we want it on or off?
Answer: It allows the page to save the users input on a form across postbacks. It saves the server-side values for a given control into ViewState, which is stored as a hidden value on the page before sending the page to the clients browser. When the page is posted back to the server the server control is recreated with the state stored in viewstate.
What are the different types of Session state management options available with ASP.NET?
Answer: ASP.NET provides In-Process and Out-of-Process state management. In-Process stores the session in memory on the web server. This requires the a "sticky-server" (or no load-balancing) so that the user is always reconnected to the same web server. Out-of-Process Session state management stores data in an external data source. The external data source may be either a SQL Server or a State Server service. Out-of-Process state management requires that all objects stored in session are serializable.
What Are the Goals of the Compact Framework?
Answer: The goals of the Compact Framework (and Smart Device Projects) are fourfold:
? To provide a portable (and small) subset of the Windows .NET Framework targeting multiple platforms. This includes the creation of a runtime engine, class libraries, and compilers for VB and C# that together are referred to as the .NET Compact Framework. This framework is not a simple port of the desktop version, but a complete rewrite designed to execute managed code on multiple CPU architectures and operating systems through an abstraction layer known as the Platform Adaption Layer (PAL). It is important to note that the Compact Framework was also designed to be a subset of the desktop version of the Framework. As a result, roughly 25% of the desktop types are represented in the Compact Framework.
?Leverage VS .NET. Since VS .NET already provides a high productivity development environment, it is only natural that this environment should be utilized in developing mobile applications as well. To that end, the Smart Device Projects for VS .NET 2003 provide the project templates, emulator, debugger, and device integration to use the same IDE for desktop as for mobile development.
? True Emulation. One of the requirements for developing robust (i.e., well-debugged) mobile applications is that they run as expected when installed on the device. To that end VS.NET includes emulators for Pocket PC and Windows CE that run exactly the same execution engine and class libraries as those installed on the device. In addition, the emulator supports localized packages for developing global applications. In this way, developers can be assured that the code they write and test with the emulator will execute correctly when deployed to the device.
?Enable Web Services on Devices. Since XML Web Services are by definition device independent, they can be used from a variety of devices. By building support for consuming web services directly into the Compact Framework, developers can easily call web services.
On Which Platforms Does It Run?
Answer: Since 1992 Microsoft has produced a series of platforms (9 if our count is correct) built on the Windows CE operating system. A platform includes a specific set of hardware coupled with a version of Windows CE and associated software that makes it easier for developers and device manufacturers to target their solutions. The Compact Framework supports the Pocket PC 2000, 2002, and embedded Windows CE .NET 4.1 platforms. Although not officially supported, Compact Framework code also runs on Pocket PC Phone Edition devices that are a superset of Pocket PC 2002. Also not supported are smartphones such as the SPV from Orange.
Because the Compact Framework is a managed environment, each device that executes applications written using the Compact Framework must have the framework installed. As of this writing, there were no devices shipping that included the Compact Framework as a standard component in RAM or in ROM. However, look for future devices running Windows CE .NET to include the runtime.
What About ASP.NET Mobile Controls (aka the Mobile Internet Toolkit)?
Answer: Many developers new to developing for mobility are at first confused by the differences between the Compact Framework and ASP.NET Mobile Controls. In a nutshell here are the primary differences.
? The ASP.NET Mobile Controls are a server side technology whereas the Compact Framework is a client side technology. This means that code written using mobile controls must execute on a server, and not directly on the device, by producing markup language that is interpreted by the device using a browser or parser. Code written for the Compact Framework executes directly on the device using just-in-time (JIT) compilation and native execution.
? The ASP.NET Mobile Controls are based on ASP.NET and use the ASP.NET HTTP runtime to handle and process requests via a set of ASP.NET server controls specially designed for small form factor devices. This means that mobile controls require an ASP.NET web server (IIS 5.0 or 6.0). The device issues requests that are processed on the web server by the controls producing markup language.
?Both ASP.NET Mobile Controls and the Compact Framework are based on the desktop Framework and VS .NET. In the case of mobile controls, developers use VS .NET to write ASP.NET code using the ASP.NET server controls. The server side code is JIT compiled and executed on the web server by the common language runtime. In the case of the Compact Framework the code is written using SDP and subsequently downloaded to the device for JITting and execution using a compact version of the common language runtime.
? The ASP.NET Mobile Controls are more flexible in that they can dynamically produce various markup languages depending on the requesting device they dynamically detect, including WML, cHTML, HTML, and XHTML (in Visual Studio .NET 2003 and the Framework v1.1). This means that mobile controls can support a broader range of devices (over 200 at last count) including wireless web phones, Pocket PCs, and virtually any device that supports HTTP and HTML. The ASP.NET Mobile Controls also include the ability to add device specific customizations so that as new devices come online their feature set can be identified.
? Since code written for the Compact Framework is downloaded to the device, the Compact Framework supports connected, occasionally connected, and disconnected scenarios and supports local data storage using XML or SQL Server 2000 Windows CE Edition. ASP.NET Mobile Controls only support the former since an HTTP connection is required to request an ASP.NET page that uses the mobile controls. Basically, this means that mobile controls are targeted for building web sites for a broad variety of connected devices and at the same time not having to rewrite the vast majority of code to deal with differences between those devices.
As a result we can (and in our estimation should) consider architecting and building your applications using the Compact Framework and SDP when the following are true.
? You are developing code that will execute on the device, as opposed to applications developed with the ASP.NET Mobile Controls
? Your applications must run in disconnected, connected, or occasionally connected modes
? You are targeting the Pocket PC 2000, 2002 or embedded Windows CE .NET platforms
What's Missing in the Compact Framework?
Answer: In order to accommodate the restricted resources on smart devices the Compact Framework was designed as a subset of the desktop libraries and in fact includes just over 1,700 types, or roughly 25% of the desktop framework. As a result, developers familiar with the desktop Framework should not expect all the functionality they are accustomed to. The most important omissions are listed here:
? ASP.NET. Because the Compact Framework is designed to support applications that execute on the device, it does not include any support for building web pages hosted on a web server running on the device.
? COM Interop. Since the Windows CE operating system and the embedded Visual C++ (eVC) tool support creating COM components and ActiveX controls, it would be nice if the Compact Framework supported the same COM Interop functionality (complete with COM callable wrappers and interop assemblies) as does the desktop Framework. Unfortunately, COM Interop did not make it into the initial release of the Compact Framework. However, it is possible to create a DLL wrapper for a COM component using eVC++ and then call the wrapper using the Platform Invoke (PInvoke) feature of the Compact Framework, which allows native APIs to be called.
? OleDb Access. The Compact Framework omits the System.Data.OleDb namespace and so does not support the ability to make calls directly to a database using the OleDb .NET Data Provider.
? Generic Serialization. The desktop Framework supports binary serialization of any object through the use of the Serializable attribute, the ISerializable interface, and the XmlSerializer class in the System.Xml.Serialization namespace. This functionality is not supported in the Compact Framework. However, the Compact Framework does support serializing objects to XML for use in XML Web Services and serializing DataSet objects to XML.
? Asynchronous Delegates. Delegates in both the desktop Framework and Compact Framework can be thought of as object-oriented function pointers. They are used to encapsulate the signature and address of a method to invoke at runtime. While delegates can be called synchronously, they cannot be invoked asynchronously and passed a callback method in the Compact Framework. However, it should be noted that asynchronous operations are supported for some of the networking functionality found in the System.Net namespace and when calling XML Web Services. In other cases, direct manipulation of threads or the use of a thread pool is required.
? .NET Remoting. In the desktop Framework, it is possible to create applications that communicate with each other across application domains using classes in the System.Runtime.Remoting namespace. This technique allows for data and objects serialized to SOAP or a binary format to be transmitted using TCP or HTTP. This functionality is not supported (in part because Generic Serialization is not supported) in the Compact Framework where instead XML Web Services and IrDA can be used.
? Reflection Emit. Although the Compact Framework does support runtime type inspection using the System.Reflection namespace, it does not support the ability to emit dynamically created MSIL into an assembly for execution.
? Printing. Although the Compact Framework does support graphics and drawing, it does not support printing through the System.Drawing.Printing namespace.
? XPath/XSLT. Support for XML is included in the Compact Framework and allows developers to read and write XML documents using the XmlDocument, XmlReader, and XmlWriter classes. However, it does not support executing XPath queries or performing XSL transformations.
? Server-side Programming Models. As you would expect, the Compact Framework also does not support the server-side programming models including System.EnterpriseServices (COM+), System.Management (WMI), and System.Messaging (MSMQ).
? Multi-module Assemblies. The desktop Framework supports the ability to deploy an assembly as a collection of files. This is useful for creating assemblies authored with multiple languages. This feature is not supported in the Compact Framework where a single file (.exe or .dll) represents the entire assembly.
However, the Compact Framework does support two additional namespaces to support features particular to smart devices (see Table 1).
In addition, support for the IrDA protocol has been included in the Compact Framework and exposed in the six classes found in the System.Net.Sockets and the System.Net namespaces.
What Do Developers Need to Learn to Use the Compact Framework Effectively?
Answer: Although VB 6.0 and embedded VB (eVB) developers will feel fairly comfortable with the VB syntax used in SDP, the object-oriented nature of the Compact Framework means that developers need to have a firm grounding in OO concepts in order to maximize their productivity.
For example, the class libraries in the Compact Framework make extensive use of both implementation and interface inheritance. Developers familiar with these concepts can not only more easily understand the framework, but can write polymorphic code using the framework that is more maintainable and flexible than the component based development typically done in eVB. In the long run, using OO in their own designs allows developers to write less code and make the code that they do write more reusable. Therefore, to take maximum advantage of OO, however, a development organization should also get up to speed on the use of design patterns.
Subscribe to:
Posts (Atom)