Monday, December 10, 2007

FAQs' on .net

If I return out of a try/finally in C#, does the code in the finally-clause run? - Yes. The code in the finally always runs. If you return out of the try block, or even if you do a “goto” out of the try, the finally block always runs

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:

_using _System;
_[_assembly _:_ _MyAttributeClass_]_ _class X _{_}_

Note that in an IDE-created project, by convention, these attributes are placed in AssemblyInfo.cs.

How do you mark a method obsolete? -
_[_Obsolete_]_ _public _int _Foo_(_)
_{..._}
or
_[_Obsolete_(_\"This is a message describing why this method is obsolete_\_")] _public _int _Foo_(_) _{...}
Note: The O in Obsolete is always capitalized.

How do you directly call a native function exported from a DLL? - Here’s a quick example of the DllImport attribute in action:

_using _System._Runtime._InteropServices; _\_
_class _C
{
_[_DllImport_(_\_"user32.dll_\_")_]
_public _static _extern _int _MessageBoxA_(_int _h, _string _m, _string _c, _int _type_);
_public _static _int _Main()
{ _return _MessageBoxA_(_0, _\_"Hello World!_\_", _\_"Caption_\_", 0);
}
}

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.

Which of these statements correctly declares a two-dimensional array in C#?
int[,] myArray;

How does assembly versioning in .NET prevent DLL Hell?
.NET allows assemblies to specify the name AND the version of any assemblies they need to run.

In the NUnit test framework, which attribute must adorn a test class in order for
it to be picked up by the NUnit GUI?
TestFixtureAttribute

Which of the following operations can you NOT perform on an ADO.NET DataSet?
A DataSet can be synchronised with the database. [CAN]
A DataSet can be synchronised with a RecordSet. [CANNOT]
A DataSet can be converted to XML. [CAN]
You can infer the schema from a DataSet. [CAN]

How can you tell the application to look for assemblies at the locations other than its own install?
Use the directive in the XML .config file for a given application.
_<_probing _privatepath_="_”_c:\mylibs;">
should do the trick.
Or you can add additional search paths in the Properties box of the deployed application.

What is delay signing?
Delay signing allows you to place a shared assembly in the GAC by signing the assembly with just the public key. This allows the assembly to be signed with the private key at a later stage, when the development process is complete and the component or assembly is ready to be deployed. This process enables developers to work with shared assemblies as if they were strongly named, and it secures the private key of the signature from being accessed at different stages of development

No comments: