Beruflich Dokumente
Kultur Dokumente
11. How can you sort the elements of the array in descending order?
By calling Sort() and then Reverse() methods.
12. What’s the .NET collection class that allows an element to be accessed using
a unique key?
HashTable.
13. What class is underneath the SortedList class?
A sorted HashTable.
14. Will the finally block get executed if an exception has not occurred?
Yes.
16. Can multiple catch blocks be executed for a single try statement?
No. Once the proper catch block processed, control is transferred to the finally block
(if there are any).
17. Explain the three services model commonly know as a three-tier application.
Presentation (UI), Business (logic and underlying code) and Data (from storage or
other sources).
Class Questions
2. Can you prevent your class from being inherited by another class?
Yes. The keyword “sealed” will prevent the class from being inherited.
3. Can you allow a class to be inherited, but prevent the method from being
over-ridden?
Yes. Just leave the class public and make the method sealed.
7. Why can’t you specify the accessibility modifier for methods inside the
interface?
They all must be public, and are therefore public by default.
1. What’s the implicit name of the parameter that gets passed into the set
method/property of a class?
Value. The data type of the value parameter is defined by whatever data type the
property is declared as.
4. Can you declare an override method to be static if the original method is not
static?
No. The signature of the virtual method must remain the same. (Note: Only the
keyword virtual is changed to keyword override)
1. Is XML case-sensitive?
Yes.
3. What’s the difference between the Debug class and Trace class?
Documentation looks the same. Use Debug class for debug builds, use Trace class for
both debug and release builds.
7. What are three test cases you should go through in unit testing?
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).
7. What does the Initial Catalog parameter define in the connection string?
The database name to connect to.
Assembly Questions
Answer: private constructors can be used when u donot want the class's object to be created.
Since the constructor cannot be accessed, an object of the class cannot be created. A possible
scenario would be , a class with static methods.. which dont need object instance to be called.
ANS: Server side code will execute at server end all the business logic will execute at
server end where as client side code will execute at client side at browser end.
3. Should validation (did the user enter a real date) occur server-side or client-side?
Why?
ANS : client side . there is no need to go to validate user input. If it relates to data
base validation we need to validate at server side.
4. What does the "EnableViewState" property do? Why would I want it on or off?
ANS: Server.Trnasfer will prevent round trip. it will redirect pages which or in the same
directory. NO way to pass the query strings . Thru http context we can able to get the
previous page control values.
6. Can you give an example of when it would be appropriate to use a web service as
opposed to a non-serviced .NET component
7. Let's say I have an existing application written using Visual Studio 6 (VB 6,
InterDev 6) and this application utilizes Windows 2000 COM+ transaction services.
How would you approach migrating this
application to .NET
We need to have Wrapper to communicate COM components in .net. and vis versa
8. Can you explain the difference between an ADO.NET Dataset and anADO
Recordset?\
ANS : DIsconnected architechure . Maintainace relation schemas. MUtilple table
grouping.
Connected one .
9. Can you give an example of what might be best suited to place in the
Application_Start and Session_Start subroutines?
ANS: APplication_start need for global variable which are available over the
application.
Sesssion_Start : login dependent ( user dependent)
10. If I'm developing an application that must accomodate multiple security levels
though secure login and my ASP.NET web appplication is
spanned across three web-servers (using round-robbin load balancing)
what would be the best approach to maintain login-in state for the
users?
ANS : Heridity.
Use the existing functionality along with its own properities.
15. Describe the difference between inline and code behind - which is best in a loosely
coupled solution
17. Explain what a diffgram is, and a good use for one
18. Where would you use an iHTTPModule, and what are the limitations of any
approach you might take in implementing one
21 Describe session handling in a webfarm, how does it work and what are the limits
ANS:
Session - mode
State sever
OUtprocess
sql
22. How would you get ASP.NET running in Apache web servers - why would you even
do this?
23. Whats MSIL, and why should my developers need an appreciation of it if at all?
ANS : Microsoft Intermeidate lanaguage. which is the out put for all the .net supported
languages after comiplation will produce.
Appreciation for cross language support.
25. Which method do you invoke on the DataAdapter control to load your generated
dataset with data?
Fill()
27. Which template must you provide, in order to display data in a Repeater control?
ITemtemplate
AlternateItemTemplate
29. 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?
Datasource,
DataBind
System.Web.UI.Page
abondon()
32 How do you turn off cookies for one page in your site?
disablecookies.
36. What tag do you use to add a hyperlink column to the DataGrid?
hyper link column
37. What is the standard you use to wrap up a call to a Web service
------------
38. Which method do you use to redirect the user to another page without performing
a round trip to the client?
server.transfer
39. What is the transport protocol you use to call a Web service SOAP
http
40. True or False: A Web service can only be written in .NET
false
41. What does WSDL stand for? webservice discription language. it is used to generate
for proxy( server object)
42. What property do you have to set to tell the grid which page to go to when using
the Pager object?
Page Index.
43. Where on the Internet would you look for Web services?
UDDI
44. What tags do you need to add within the asp:datagrid tags to bind columns
manually.
Autogenerate columns
45. 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?
datatext
datavalue
48. True or False: To test a Web service you must create a windows application or Web
application to consume this service?
no
49. How many classes can a single .NET DLL contain?
as many as u want..
37. What is the standard you use to wrap up a call to a Web service
Ans:SOAP
It is available to classes that are within the same assembly and derived from the
specified base class. - THIS IS WRONG.
Both “In Try block” and “In Finally block” will be displayed. Whether the return
is in the try block or after the try-finally block, performance is not affected either
way. The compiler treats it as if the return were outside the try block anyway. If
it’s a return without an expression (as it is above), the IL emitted is identical
whether the return is inside or outside of the try. If the return has an expression,
there’s an extra store/load of the value of the expression (since it has to be
computed within the try block).
21. I was trying to use an “out int” parameter in one of my functions. How
should I declare the variable that I am passing to it? - You should declare the
variable as an int, but when you pass it in you must specify it as ‘out’, like the
following: int i; foo(out i); where foo is declared as follows: [return-type] foo(out
int o) { }
22. How does one compare strings in C#? - In the past, you had to call .ToString()
on the strings when using the == or != operators to compare the strings’ values.
That will still work, but the C# compiler now automatically compares the values
instead of the references when the == or != operators are used on string types. If
you actually do want to compare references, it can be done as follows: if ((object)
str1 == (object) str2) { … } Here’s an example showing how string compares
work:
23.using System;
24.public class StringTest
25.{
26. public static void Main(string[] args)
27. {
28. Object nullObj = null; Object realObj = new
StringTest();
29. int i = 10;
30. Console.WriteLine("Null Object is [" + nullObj + "]\n"
31. + "Real Object is [" + realObj + "]\n"
32. + "i is [" + i + "]\n");
33. // Show string equality operators
34. string str1 = "foo";
35. string str2 = "bar";
36. string str3 = "bar";
37. Console.WriteLine("{0} == {1} ? {2}", str1, str2, str1
== str2 );
38. Console.WriteLine("{0} == {1} ? {2}", str2, str3, str2
== str3 );
39. }
40.}
Output:
Null Object is []
Real Object is [StringTest]
i is [10]
foo == bar ? False
bar == bar ? True
41. How do you specify a custom attribute for the entire assembly (rather than
for a class)? - Global attributes must appear after any top-level using clauses and
before the first type or namespace declarations. An example of this is as follows:
42.using System;
43.[assembly : MyAttributeClass] class X {}
or
try {
CriticalSection.Enter(obj);
// code
}
finally
{
CriticalSection.Exit(obj);
}
47. How do you directly call a native function exported from a DLL? - Here’s a
quick example of the DllImport attribute in action:
48.using System.Runtime.InteropServices; \
49.class C
50.{
51. [DllImport("user32.dll")]
52. public static extern int MessageBoxA(int h, string m, string c,
int type);
53. public static int Main()
54. {
55. return MessageBoxA(0, "Hello World!", "Caption", 0);
56. }
57.}
This example shows the minimum requirements for declaring a C# method that is
implemented in a native DLL. The method C.MessageBoxA() is declared with the
static and external modifiers, and has the DllImport attribute, which tells the
compiler that the implementation comes from the user32.dll, using the default
name of MessageBoxA. For more information, look at the Platform Invoke
tutorial in the documentation.
58. How do I simulate optional parameters to COM calls? - You must use the
Missing class and pass Missing.Value (in System.Reflection) for any values that
have optional parameters.
59. What’s the advantage of using System.Text.StringBuilder over
System.String? StringBuilder is more efficient in the cases, where a lot of
manipulation is done to the text. Strings are immutable, so each time it’s being
operated on, a new instance is created.
60. Can you store multiple data types in System.Array? No.
61. What’s the difference between the System.Array.CopyTo() and
System.Array.Clone()? The first one performs a deep copy of the array, the
second one is shallow.
62. How can you sort the elements of the array in descending order? By calling
Sort() and then Reverse() methods.
63. What’s the .NET datatype that allows the retrieval of data by a unique key?
HashTable.
64. What’s class SortedList underneath? A sorted HashTable.
65. Will finally block get executed if the exception had not occurred? Yes.
66. 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 {}.
67. Can multiple catch blocks be executed? No, once the proper catch code fires
off, the control is transferred to the finally block (if there are any), and then
whatever follows the finally block.
68. Why is it a bad idea to throw your own exceptions? Well, if at that point you
know that an error has occurred, then why not write the proper code to handle that
error instead of passing a new Exception object to the catch block? Throwing your
own exceptions signifies some design flaws in the project.
69. What’s a delegate? A delegate object encapsulates a reference to a method. In
C++ they were referred to as function pointers.
70. What’s a multicast delegate? It’s a delegate that points to and eventually fires
off several methods.
71. How’s the DLL Hell problem solved in .NET? 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.
72. What are the ways to deploy an assembly? An MSI installer, a CAB archive,
and XCOPY command.
73. What’s a satellite assembly? When you 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.
74. What namespaces are necessary to create a localized application?
System.Globalization, System.Resources.
75. What’s the difference between // comments, /* */ comments and ///
comments? Single-line, multi-line and XML documentation comments.
76. How do you generate documentation from the C# file commented properly
with a command-line compiler? Compile it with a /doc switch.
77. What’s the difference between <c> and <code> XML documentation tag?
Single line code example and multiple-line code example.
78. Is XML case-sensitive? Yes, so <Student> and <student> are different elements.
79. What debugging tools come with the .NET SDK? CorDBG – command-line
debugger, and DbgCLR – graphic debugger. Visual Studio .NET uses the
DbgCLR. To use CorDbg, you must compile the original C# file using the /debug
switch.
80. What does the This window show in the debugger? It points to the object that’s
pointed to by this reference. Object’s instance data is shown.
81. What does assert() do? 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.
82. What’s the difference between the Debug class and Trace class?
Documentation looks the same. Use Debug class for debug builds, use Trace
class for both debug and release builds.
83. Why are there five tracing levels in System.Diagnostics.TraceSwitcher? The
tracing dumps can be quite verbose and for some applications that are constantly
running you run the risk of overloading the machine and the hard drive there. Five
levels range from None to Verbose, allowing to fine-tune the tracing activities.
84. Where is the output of TextWriterTraceListener redirected? To the Console or
a text file depending on the parameter passed to the constructor.
85. How do you debug an ASP.NET Web application? Attach the aspnet_wp.exe
process to the DbgClr debugger.
86. What are three test cases you should go through in unit testing? Positive test
cases (correct data, correct output), negative test cases (broken or missing data,
proper handling), exception test cases (exceptions are thrown and caught
properly).
87. Can you change the value of a variable while debugging a C# application?
Yes, if you are debugging via Visual Studio.NET, just go to Immediate window.
88. Explain the three services model (three-tier application). Presentation (UI),
business (logic and underlying code) and data (from storage or other sources).
89. What are advantages and disadvantages of Microsoft-provided data provider
classes in ADO.NET? 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, but it’s a .NET layer on top of OLE layer, so not the fastest thing in the
world. ODBC.NET is a deprecated layer provided for backward compatibility to
ODBC engines.
90. What’s the role of the DataReader class in ADO.NET connections? It returns a
read-only dataset from the data source when the command is executed.
91. What is the wildcard character in SQL? Let’s say you want to query
database with LIKE for all employees whose name starts with La. The
wildcard character is %, the proper query with LIKE would involve ‘La%’.
92. Explain ACID rule of thumb for transactions. Transaction must be Atomic (it
is one unit of work and does not dependent on previous and following
transactions), Consistent (data is either committed or roll back, no “in-between”
case where something has been updated and something hasn’t), Isolated (no
transaction sees the intermediate results of the current transaction), Durable (the
values persist if the data had been committed even if the system crashes right
after).
93. What connections does Microsoft SQL Server support? Windows
Authentication (via Active Directory) and SQL Server authentication (via
Microsoft SQL Server username and passwords).
94. Which one is trusted and which one is untrusted? 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.
95. Why would you use untrusted verificaion? Web Services might use it, as well
as non-Windows applications.
96. What does the parameter Initial Catalog define inside Connection String?
The database name to connect to.
97. What’s the data provider name to connect to Access database?
Microsoft.Access.
98. What does Dispose method do with the connection object? Deletes it from the
memory.
99. What is a pre-requisite for connection pooling? Multiple processes must agree
that they will share the same connection, where every parameter is the same,
including the security settings.
OR
A nested class is any class whose declaration occurs within the body of another class or
interface.
An OS process provides isolation by having a distinct memory address space. While this is
effective, it is also expensive, and does not scale to the numbers required for large web servers.
The Common Language Runtime, on the other hand, enforces application isolation by managing
the memory use of code running within the application domain. This ensures that it does not
access memory outside the boundaries of the domain. It is important to note that only type-safe
code can be managed in this way (the runtime cannot guarantee isolation when unsafe code is
loaded in an application domain).
If I want to build a shared assembly, does that require the overhead of signing
and managing key pairs?
Posted by: Rohitshah | Show/Hide Answer
Building a shared assembly does involve working with cryptographic keys. Only the public key is
strictly needed when the assembly is being built. Compilers targeting the .NET Framework
provide command line options (or use custom attributes) for supplying the public key when
building the assembly. It is common to keep a copy of a common public key in a source database
and point build scripts to this key. Before the assembly is shipped, the assembly must be fully
signed with the corresponding private key. This is done using an SDK tool called SN.exe (Strong
Name).
Strong name signing does not involve certificates like Authenticode does. There are no third party
organizations involved, no fees to pay, and no certificate chains. In addition, the overhead for
verifying a strong name is much less than it is for Authenticode. However, strong names do not
make any statements about trusting a particular publisher. Strong names allow you to ensure that
the contents of a given assembly haven't been tampered with, and that the assembly loaded on
your behalf at run time comes from the same publisher as the one you developed against. But it
makes no statement about whether you can trust the identity of that publisher.
What is Attribute Programming? What are attributes? Where are they used?
Posted by: Rohitshah | Show/Hide Answer
Attributes are a mechanism for adding metadata, such as compiler instructions and other data
about your data, methods, and classes, to the program itself. Attributes are inserted into the
metadata and are visible through ILDasm and other metadata-reading tools. Attributes can be
used to identify or use the data at runtime execution using .NET Reflection.
Q3: Describe the Asp.net pipeline ? Give an Example when you need to extend it?
How do you do so?
A3: http://msdn.microsoft.com/msdnmag/issues/02/09/HTTPPipelines/
Q9: What do you know about ATLAS (Microsoft ASP.net AJAX Extensions) ?
A9: for more information check here, http://ajax.asp.net
Q19: Without using the multiplication or addition operations, how can you multiply
a number x by 8?
A19: Shift x to the left 3 times, x << 3, because every shift left multiplies the number by
2
Q20: What is the difference between ASP.net 1.x & ASP.net 2.0 ?
A20: Any answer that include stuff like Provider model (membership provider, role
provider ... etc) and Master Pages, Code Beside model, new web controls will be ok.
If you have more questions feel free to join the user group and add them directly to the
database.
Comments
# re: .Net & C# Interview question, along with general programming questions
Tuesday, February 27, 2007 9:11 AM by Mohamed Tanna
More Interview question
-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.
11-How can you sort the elements of the array in descending order?
-By calling Sort() and then Reverse() methods.
12-What happens if you inherit multiple interfaces and they have conflicting method
names?
-It’s up to you to implement the method inside your own class, so implementation is left
entirely up to you. This might cause a problem on a higher-level scale if similarly named
methods from different interfaces expect different data, but as far as compiler cares
you’re okay.
To Do: Investigate
13-If a base class has a number of overloaded constructors, and an inheriting class has a
number of overloaded constructors; can you enforce a call from an inherited constructor
to a specific base constructor?
-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.
-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.
9) Define encapsulation?
Encapsulation literally means to enclose in or as if in a capsule. Encapsulation is defined as the
process of enclosing one or more items within a physical or logical package. It involves
preventing access to nonessential details.
The private access specifier allows a class to hide its member variables and member functions
from other class objects and functions. Therefore, the private member of a class is not visible
outside a class. If a member is declared private, only the functions of that class can access the
member. Even the instance of the class cannot access its members