Saturday, October 27, 2007

New series of Microsoft Webcasts

Communities and webcasts are great place to learn and share .Is not it?

Here are new series of webcasts for IT PRO by eminent speakersPlease register the corresponding stream.

October 15, 2007(4:00 pm - 5:30 pm)

Infrastructure Architecture - Case Study Review
Infrastructure Architecture - Case Study Review.

Speaker: Ramnish SinghOctober 17, 2007(2:00 pm - 3:00 pm)

SQL Server 2005 - BasicsThis session we will take a look at the various SQL Server 2005 Editions available in the market. We will then take a dive into the various sub-components introduced with SQL Server 2005. The session will build the foundation for getting started with SQL Server 2005.

Speaker:
Vinod Kumar October 18, 2007(4:00 pm - 5:30 pm)

SQL Server 2005: Database MaintenanceAlthough many of the concepts of database maintenance in a SQL Server 2005 Environment remain the same as with previous SQL releases, there are several new features. Database snapshots provide a way to revert to a point of consistency, while partial restores allows users to access unaffected files and pages. You can now continue the backup and restore operations after a failure and configure fast recovery during crash recovering and mirroring failover. It is now possible to verify the integrity of data pages during backup and restore operations. Come, hear about all of these and see some of these features in action with me!

Speaker: L Srividya October 19, 2007(4:00 pm - 5:30 pm)

Monitoring SQL Server 2005 PerformanceA number of tools are available to inspect and record activity in a SQL Server installation. Some are built into SQL Server and some are built into the Operating System. Some of these tools include the System monitor, Data Tuning Advisor, Activity Monitor, etc. This session takes you through a few of these tools for troubleshooting and optimizing your SQL Server performance.

Class and structure

What are similarities between Class and structure ?

Following are the similarities between classes and structures :-v Both can have constructors, methods, properties, fields, constants,enumerations, events, and event handlers.v Structures and classes can implement interface.v Both of them can have constructors with and without parameter.v Both can have delegates and events.(A) What is the difference between Class and structure’s ?Following are the key differences between them :-v Structure are value types and classes are reference types. So structures usestack and classes use heap.v Structures members can not be declared as protected, but class members canbe. You can not do inheritance in structures.v Structures do not require constructors while classes require.v Objects created from classes are terminated using Garbage collector. Structuresare not destroyed using GC.

Cache

(B) What is application object ?
Application object can used in situation where we want data to be shared across users globally.
(I)What’s the difference between Cache object and application object ?
The main difference between the Cache and Application objects is that the Cache object provides cache-specific features, such as dependencies and expiration policies.
(I)How can get access to cache object ?
The Cache object is defined in the System.Web.Caching namespace. You can get a reference to the Cache object by using the Cache property of the HttpContext class in the System.Web namespace or by using the Cache property of the Page object.
(A)What are dependencies in cache and types of dependencies ?
When you add an item to the cache, you can define dependency relationships that can force that item to be removed from the cache under specific activities of
dependencies.Example if the cache object is dependent on file and when the file data changes you want the cache object to be update.Following are the supported dependency
:-
√ File dependency :- Allows you to invalidate a specific cache item when a disk
based file or files change.
√ Time-based expiration :- Allows you to invalidate a specific cache item
depending on predefined time.
√ Key dependency :-Allows you to invalidate a specific cache item depending
when another cached item changes.
(P)Can you show a simple code showing file dependency in cache ?
Partial Class Default_aspx
Public Sub displayAnnouncement()
Dim announcement As String
If Cache(“announcement”) Is Nothing Then
Dim file As New _
System.IO.StreamReader _
(Server.MapPath(“announcement.txt”))
announcement = file.ReadToEnd
file.Close()
Dim depends As New _
System.Web.Caching.CacheDependency _
(Server.MapPath(“announcement.txt”))
Cache.Insert(“announcement”, announcement, depends)
End If
Response.Write(CType(Cache(“announcement”), String))
End Sub
Private Sub Page_Init(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Init
displayAnnouncement()
End Sub
End Class
Note :- Above source code can be obtained from CD in “CacheSample”
folder.”Announcement.txt” is in the same folder which you can play around to see the
results.
Above given method displayAnnouncement() displays banner text from Announcement.txt file which is lying in application path of the web directory.Above method first checks is the Cache object nothing , if the cache object is nothing then it moves further to load the cache data from the file.Whenever the file data changes the cache object is removed and
set to nothing.
(A) What is Cache Callback in Cache ?
Cache object is dependent on its dependencies example file based , time based etc.Cache items remove the object when cache dependencies change.ASP.NET provides capability to execute a callback method when that item is removed from cache.


(B) What are different types of caching using cache object of ASP.NET?
You can use two types of output caching to cache information that is to be transmitted to
and displayed in a Web browser:
√ Page Output Caching
Page output caching adds the response of page to cache object.Later when
page is requested page is displayed from cache rather than creating the
page object and displaying it.Page output caching is good if the site is
fairly static.
√ Page Fragment Caching
If parts of the page are changing, you can wrap the static sections as user
controls and cache the user controls using pagefragment caching.
(B) How can you cache different version of same page using ASP.NET
cache object ?
Output cache functionality is achieved by using “OutputCache” attribute on ASP.NET
page header.Below is the syntax
<%@ OutputCache Duration="20" Location="Server" VaryByParam="state" VaryByCustom="minorversion" VaryByHeader="Accept-Language"%>
√ VaryByParam :- Caches different version depending on input parameters send
through HTTP POST/GET.
√ VaryByHeader:- Caches different version depending on the contents of the
page header.


(A) How will implement Page Fragment Caching ?
Page fragment caching involves the caching of a fragment of the page, rather than the
entire page. When portions of the page need to be dynamically created for each user
request this is best method as compared to page caching.You can wrap Web Forms user
control and cache the control so that these portions of the page don’t need to be recreated
each time.
(B) What are ASP.NET session and compare ASP.NET session with
classic ASP session variables?
ASP.NET session caches per user session state.It basically uses “HttpSessionState” class.
Following are the limitations in classic ASP sessions :-
√ ASP session state is dependent on IIS process very heavily.So if IIS restarts
ASP session variables are also recycled.ASP.NET session can be independent
of the hosting environment thus ASP.NET session can maintained even if IIS
reboots.
√ ASP session state has no inherent solution to work with Web Farms.ASP.NET
session can be stored in state server and SQL SERVER which can support
multiple server.
√ ASP session only functions when browser supports cookies.ASP.NET session
can be used with browser side cookies or independent of it.
(B) Which various modes of storing ASP.NET session ?
√ InProc:- In this mode Session state is stored in the memory space of the
Aspnet_wp.exe process.This is the default setting.If the IIS reboots or web
application restarts then session state is lost.
√ StateServer:-In this mode Session state is serialized and stored in a separate
process (Aspnet_state.exe); therefore, the state can be stored on a separate
computer(a state server).
√ SQL SERVER:- In this mode Session state is serialized and stored in a SQL
Server database.
Session state can be specified in element of application configuration file.Using State Server and SQL SERVER session state can be shared across web farms but note this comes at speed cost as ASP.NET needs to serialize and deserialize data over network again and again.
(B) What are the other ways you can maintain state ?
Other than session variables you can use the following technique to store state :
√ Hidden fields
√ View state
√ Hidden frames
√ Cookies
√ Query strings
(B) What are benefits and Limitation of using Hidden fields ?
Following are the benefits of using Hidden fields :-
√ They are simple to implement.
√ As data is cached on client side they work with Web Farms.
√ All browsers support hidden field.
√ No server resources are required.
Following are limitations of Hidden field :-

C# for All Interviews.

Interview questions for C# developers

Is it possible to inline assembly or IL in C# code? - No.

Is it possible to have different access modifiers on the get/set methods of a property? - No. The access modifier on a property applies to both its get and set accessors. What you need to do if you want them to be different is make the property read-only (by only providing a get accessor) and create a private/internal set method that is separate from the property.

Is it possible to have a static indexer in C#? - No. Static indexers are not allowed in C#.

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:
using System;

class main
{
public static void Main()
{
try
{
Console.WriteLine(\"In Try block\");
return;
}
finally
{
Console.WriteLine(\"In Finally block\");
}
}
}
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).

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) { }

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:
using System;
public class StringTest
{
public static void Main(string[] args)
{
Object nullObj = null; Object realObj = new StringTest();
int i = 10;
Console.WriteLine(\"Null Object is [\" + nullObj + \"]\n\"
+ \"Real Object is [\" + realObj + \"]\n\"
+ \"i is [\" + i + \"]\n\");
// Show string equality operators
string str1 = \"foo\";
string str2 = \"bar\";
string str3 = \"bar\";
Console.WriteLine(\"{0} == {1} ? {2}\", str1, str2, str1 == str2 );
Console.WriteLine(\"{0} == {1} ? {2}\", str2, str3, str2 == str3 );
}
}
Output:
Null Object is []
Real Object is [StringTest]
i is [10]
foo == bar ? False
bar == bar ? True

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 implement thread synchronization (Object.Wait, Notify,and CriticalSection) in C#? - You want the lock statement, which is the same as Monitor Enter/Exit:
lock(obj) { // code }
translates to
try {
CriticalSection.Enter(obj);
// code
}
finally
{
CriticalSection.Exit(obj);
}

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.

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.

Are private class-level variables inherited?
Yes, but they are not accessible, so looking at it you can honestly say that they are not inherited. But they are.

Why does DllImport not work for me?
All methods marked with the DllImport attribute must be marked as public static extern.

Why does my Windows application pop up a console window every time I run it?
Make sure that the target type set in the project properties setting is set to Windows Application, and not Console Application. If you’re using the command line, compile with /target:winexe, not /target:exe.

Why do I get an error (CS1006) when trying to declare a method without specifying a return type?
If you leave off the return type on a method declaration, the compiler thinks you are trying to declare a constructor. So if you are trying to declare a method that returns nothing, use void. The following is an example: // This results in a CS1006 error public static staticMethod (mainStatic obj) // This will work as wanted public static void staticMethod (mainStatic obj)

Why do I get a syntax error when trying to declare a variable called checked?
The word checked is a keyword in C#.
Why do I get a security exception when I try to run my C# app?
Some security exceptions are thrown if you are working on a network share. There are some parts of the frameworks that will not run if being run off a share (roaming profile, mapped drives, etc.). To see if this is what’s happening, just move the executable over to your local drive and see if it runs without the exceptions. One of the common exceptions thrown under these conditions is System.Security.SecurityException. To get around this, you can change your security policy for the intranet zone, code group 1.2, (the zone that running off shared folders falls into) by using the caspol.exe tool.

Why do I get a CS5001: does not have an entry point defined error when compiling?
The most common problem is that you used a lowercase ‘m’ when defining the Main method. The correct way to implement the entry point is as follows: class test { static void Main(string[] args) {} }

What optimizations does the C# compiler perform when you use the /optimize+ compiler option?
The following is a response from a developer on the C# compiler team: We get rid of unused locals (i.e., locals that are never read, even if assigned). We get rid of unreachable code. We get rid of try-catch with an empty try. We get rid of try-finally with an empty try. We get rid of try-finally with an empty finally. We optimize branches over branches: gotoif A, lab1 goto lab2: lab1: turns into: gotoif !A, lab2 lab1: We optimize branches to ret, branches to next instruction, and branches to branches.

What is the syntax for calling an overloaded constructor within a constructor (this() and constructorname() does not compile)?
The syntax for calling another constructor is as follows: class B { B(int i) { } } class C : B { C() : base(5) // call base constructor B(5) { } C(int i) : this() // call C() { } public static void Main() {} }
What is the equivalent to regsvr32 and regsvr32 /u a file in .NET development? - Try using RegAsm.exe. Search MSDN on Assembly Registration Tool.

What is the difference between a struct and a class in C#?
From language spec: The list of similarities between classes and structs is as follows. Longstructs can implement interfaces and can have the same kinds of members as classes. Structs differ from classes in several important ways; however, structs are value types rather than reference types, and inheritance is not supported for structs. Struct values are stored on the stack or in-line. Careful programmers can sometimes enhance performance through judicious use of structs. For example, the use of a struct rather than a class for a Point can make a large difference in the number of memory allocations performed at runtime. The program below creates and initializes an array of 100 points. With Point implemented as a class, 101 separate objects are instantiated-one for the array and one each for the 100 elements.

My switch statement works differently than in C++! Why?
C# does not support an explicit fall through for case blocks. The following code is not legal and will not compile in C#:
switch(x)
{
case 0: // do something
case 1: // do something as continuation of case 0
default: // do something in common with
//0, 1 and everything else
break;
}
To achieve the same effect in C#, the code must be modified as shown below (notice how the control flows are explicit):
class Test
{
public static void Main() {
int x = 3;
switch(x)
{
case 0: // do something
goto case 1;
case 1: // do something in common with 0
goto default;
default: // do something in common with 0, 1, and anything else
break;
}
}
}

C# does support fall through. The following code is valid:

switch (x)
{
case 0: // do something
case 1: // do something as continuation of case 0
default: // do something in common with
//0, 1 and everything else
{
break;
}
}

What C# does not allow is falling out of one code block into another like this:
// will not compile because each code block needs
// a break statement.
switch (x)
{
case 0:
{
Console.WriteLine(”0″);
}
case 1:
{
Console.WriteLine(”0″);
}
}

switch (x)
{
case 0: // do something
case 1: // do something as continuation of case 0
default: // do something in common with
//0, 1 and everything else
{
break;
}
}

C# does not support explicit fall through for the Case ….you can use goto:Case/goto:default to make a fall through
ex
swich(x)
case 1:
//do spmething ;
break;
case 2: //do somethin
goto case1;
case 3 : //do spmething ;
break;
case default : //do spmething ;
break;

Fall through is achieved like this. Do not put any code except in the case 2 to achieve the fall through.
switch(i)
{
case 0:
case 1:
case 2:
//Some code here
break;
case 5:
//some code here
break;
default:
}

Is there regular expression (regex) support available to C# developers? - Yes. The .NET class libraries provide support for regular expressions.
Look at the System.Text.RegularExpressions namespace.
Is there any sample C# code for simple threading? - Yes:
using System;
using System.Threading;
class ThreadTest
{
public void runme()
{
Console.WriteLine(\"Runme Called\");
}
public static void Main(String[] args)
{
ThreadTest b = new ThreadTest();
Thread t = new Thread(new ThreadStart(b.runme));
t.Start();
}
}
Is there an equivalent of exit() for quitting a C# .NET application? –
Yes, you can use System.Environment.Exit(int exitCode) to exit the application or Application.Exit() if it’s a Windows Forms app.

Is there a way to force garbage collection?
Yes. Set all references to null and then call System.GC.Collect(). If you need to have some objects destructed, and System.GC.Collect() doesn’t seem to be doing it for you, you can force finalizers to be run by setting all the references to the object to null and then calling System.GC.RunFinalizers().

Is there a way of specifying which block or loop to break out of when working with nested loops?
he easiest way is to use goto:
using System;
class BreakExample
{
public static void Main(String[] args) {
for(int i=0; i<3; j="0" j ="="" s =" #”n" s =" “’n" s =" @”n" s =" “n" a ="="" a =" new" instance ="="" instance =" new" instance =" new" unrestricted="true)]" cppname =" new" cppname =" new" privatepath="”c:\mylibs;">
should do the trick. Or you can add additional search paths in the Properties box of the deployed application.

How can you debug failed assembly binds?
Use the Assembly Binding Log Viewer (fuslogvw.exe) to find out the paths searched.
Where are shared assemblies stored? Global assembly cache.

How can you create a strong name for a .NET assembly?
With the help of Strong Name tool (sn.exe).

Where’s global assembly cache located on the system?
Usually C:\winnt\assembly or C:\windows\assembly.

Can you have two files with the same file name in GAC?
Yes, remember that GAC is a very special folder, and while normally you would not be able to place two files with the same name into a Windows folder, GAC differentiates by version number as well, so it’s possible for MyApp.dll and MyApp.dll to co-exist in GAC if the first one is version 1.0.0.0 and the second one is 1.1.0.0.
So let’s say I have an application that uses MyApp.dll assembly, version 1.0.0.0. There is a security bug in that assembly, and I publish the patch, issuing it under name MyApp.dll 1.1.0.0. How do I tell the client applications that are already installed to start using this new MyApp.dll? Use publisher policy. To configure a publisher policy, use the publisher policy configuration file, which uses a format similar app .config file. But unlike the app .config file, a publisher policy file needs to be compiled into an assembly and placed in the GAC.

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.

ASP.NET interview questions

Whats an assembly?
Assemblies are the building blocks of .NET Framework applications; they form the fundamental unit of deployment, version control, reuse, activation scoping, and security permissions. An assembly is a collection of types and resources that are built to work together and form a logical unit of functionality. An assembly provides the common language runtime with the information it needs to be aware of type implementations. To the runtime, a type does not exist outside the context of an assembly.

Describe the difference between inline and code behind - which is best in a loosely coupled solution?
ASP.NET supports two modes of page development: Page logic code that is written inside