Thursday, January 28, 2010

FAQ-3

1. ctype(123.34,integer) - should it throw an error? Why or why not?
No,It is valid conversion

2. directcast(123.34,integer) - should it throw an error? Why or why not?
Yes,doulbe is not inhertited from integer both are of not same types,

3. Difference between a sub and a function
Sub doesnt return value,Where as function Returns

4. Explain manifest & metadata.
Manifest describes Assembly,security,Versioning,Culture,StrongNames
Metadata destcribes content in Assembly ,classes,enums,interfaces

5.What happens in memory when you Box and Unbox a value-type
Boxing converts valuetype to reference type ,thus storing object to heap.
Unboxing converts reference type to Value Type thus storing object on Stack.

6.What namespaces are necessary to create a localized application?
System.Resources

7.What namespaces are required to work with dll?
System.InteropServices.

8.Scope of public/private/internal/protected/protected internal
public
The type or member can be accessed by any other code in the same assembly or another assembly that references it.
private
The type or member can only be accessed by code in the same class or struct.
protected
The type or member can only be accessed by code in the same class or struct, or in a derived class.
internal
The type or member can be accessed by any code in the same assembly, but not from another assembly.
protected internal
The type or member can be accessed by any code in the same assembly, or by any derived class in another assembly.

9.Difference between imperative and interrogative code

Imperative -Return value
Interrogative -Doesnot return value

10.What is Raise event
Raise Event is used for raising events. ex raising control event from main page .
11.Describe ways of cleaning up objects
GC.collect
Finalize
Dispose methods

12.Where does Dispose method lie?
The dispose method is available in System.IDisposable interface.If you want to provide cleanup mechanism then implement this interface and provide the definition for dispose() method

13.Can you configure a .NET Remoting object via XML file?
Yes, via machine.config and web.config in ASP.NET. Application-level XML settingstake precedence over machine.config.

14.Explain Web.config Settings for exception management in ASP.NET.

You should configure exception management settings within your application's Web.config file. The following is an example of the exception settings in a Web.config file.
< defaultredirect="http://hostname/error.aspx" mode="On">
< statuscode="500" redirect="/errorpages/servererror.aspx">
< statuscode="404" redirect="/errorpages/filenotfound.htm">
< /customErrors>

In the customErrors element, specify a default redirect page. There are three modes for the default redirect page:
On -Unhandled exceptions will redirect the user to the specified defaultredirect page. This is used mainly in production.
Off-Users will see the exception information and not be redirected to the defaultredirect page. This is used mainly in development.
RemoteOnly- Only users accessing the site on the local machine (using localhost) will see the exception information while all other users will be redirected to the defaultredirect page. This is used mainly for debugging.

15.What are Generics?
Generics are used to have Typed Arrays.
Ex: if we have define that an array is confined to products.if we push objects of product into array it accepts.if we push employee objects into this array it will showerror . since the type of the array is product

17.What is Global Assembly Cache (GAC) and what is the Purpose of it?
The GAC or the Global Assembly Cache in .NET Framework acts as the central place for registering assemblies.It enables you to share assemblies across numerous applications

18.How to find methods of a assembly file not using ILDASM
Using system.reflection

19.What is use of ContextUtil class?
ContextUtil is the preferred class to use for obtaining COM+ context information.

20.How do you turn off cookies for one page in your site?
Cookie.Discard

Difference between DirectCast and CType


The difference between the two keywords is that CType succeeds as long as there is a valid conversion defined between the expression and the type and DirectCast requires that the run-time type of an object variable to be the same as the specified type that it's being cast to.


The first thing to understand is that CType and DirectCast are not the same thing. Only CType can convert the underlying object to a new instance of an object of a different type. For example, if you want to turn an integer into a string. Since an Integer doesn't inherit a String, a new instance of a String object must be created in order to store the number as a String. CType can do this, DirectCast cannot. Note: There are other ways to do this too such as the
Convert.ToString method or CStr().


Dim MyInt As Integer = 123
Dim MyString1 As String = CType(MyInt, String)
Dim MyString2 As String = DirectCast(MyInt, String) ' This will not work


What DirectCast and CType do have in common is their ability to convert an object to a new type based on inheritance or implementation.

For example, if you have a String but it is stored in a variable of type Object, you can use DirectCast or CType to treat that variable as an object of type String because type String inherits type Object. In this case, the underlying data in memory is not actually changing, nor is any processing happening on that data.

Dim MyObject As Object = "Hello World"
Dim MyString1 As String = CType(MyObject, String)
Dim MyString2 As String = DirectCast(MyObject, String) ' This will work,since string is inherited from object


Retrieving Hierarchical Data in SQL

Hi,

I am adding the stored procedure to retrieve hierarchical data,
Scenario:
Employees working under manager
**********************************************************

USE [SampleDB]
GO
/****** Object: StoredProcedure [dbo].[ShowHierarchy] Script Date: 01/28/2010 17:45:51 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROC [dbo].[ShowHierarchy]
(
@Root int
)
AS
BEGIN
SET NOCOUNT ON
DECLARE @EmpID int, @EmpName varchar(30)
-- SET @EmpName = (SELECT H_Firstname FROM dbo.LM_EmployeeDetails WHERE H_ID = @Root)
(SELECT @EmpName=H_Firstname FROM EmployeeDetails WHERE ID = @Root)
PRINT REPLICATE('-', @@NESTLEVEL * 4) + @EmpName
SET @EmpID = (SELECT MIN(H_ID) FROM EmployeeDetails WHERE Manager_ID = @Root)
WHILE @EmpID IS NOT NULL
BEGIN
EXEC dbo.ShowHierarchy @EmpID
SET @EmpID = (SELECT MIN(H_ID) FROM EmployeeDetails WHERE Manager_ID = @Root AND ID > @EmpID)
print @empid
END
END


***************************************************
Pass employeeId as parameter to get tree structure of subbordinates working under the employee.

C#.net FAQ

1. Are C# constructors inherited?
No. C# constructors cannot be inherited.

2.Are C# parameters passed by reference or by value?
Default By value

3.Can a property have different get and set access?
Previous version of .net 2.0 nofor others we can have.

4.Can const and static be used together?
No. constant are implicitly static declaring again as static leads confusion

5.Can I directly call a native function exported from a DLL?
Yes.
The following example uses the minimum requirements for declaring a C# method implemented in a native DLL.

using System.Runtime.InteropServices;
class Test{ [DllImport("user32.dll")]
public static extern int MessageBoxT (int h, string m, string c, int type);
public static int Main()
{ return MessageBoxT(0, "Hello, World!", "Title", 0); }
}


The method Test.MessageBoxT() is declared with static and external modifiers. And, it has the DllImport attribute which notifies the compiler that the implementation comes from the user32.dll under the default name of MessageBoxT.

6.How can I force garbage collection?
GC.Collect()

7.How can I output simple debugging messages?
Trace.write methods of Syste.diagnostics class

8.How can one constructor call another?
To call one C# constructor from another, before the body of the constructor, use either:
: base (parameters)to call a constructor in the base class; or:
: this (parameters)

9. How check the object type at runtime?
The is keyword is used for this purpose.
Isinteger

10.How can type name clashes be resolved?
The C# using keyword can be used to supply hints to the C# compiler regarding the fully qualified names of types residing in a specified source (.cs) file. The using keyword can include an alias which can be used to prevent or resolve name clashes.

11.How do destructors work in C#?
A destructor is a method that is called when an object is destroyed—it's memory is marked unused. In .NET, the Garbage Collector (GC) performs much of this type of work automatically

12.How do I declare an out variable?
An out parameter is used to return a value in the same variable which was passed in as a parameter to the method. Any changes made to the parameter are reflected in the variable

13.How do I get DllImport to work?
Reference System.Runtime.InteropServices. Mark all methods with the DllImport attribute as public static extern.

14.How do I make a C# DLL?
Use the /target:library compiler option.
In Visual Studio,
open the Project File's property page;
open CommonProperties -> General -> Output Type;
change the output type to class library;
build the application to create a .dll file.

15.How do I use trace and assert?
Checks for a condition; if the condition is false, displays a message box that shows the call stack.

16.How get the type name at runtime?
To get the name of a C# type at runtime, use the GetType() method of object class.

17.How keep a local variable in scope across a try-catch block?
Decalre outside try block

18.How make sure C# classes will interoperate with other .NET languages?
Ensure that the C# application code conforms to the CLS.To help achieve compliance, add the [assembly:CLSCompliant(true)] global attribute to all C# source files. This attribute will cause the C# compiler to throw an error if a non-CLS-compliant feature is used.

19.How perform a case insensitive string comparison?
Stirng.compare()

20.How do you declare Global variables?
Using session variables.

21.What is a type alias?
C# defines a number of aliases for intrinsic CLR types. Aliases and types can be used interchangably. They can be mixed together in a single statement

22.What is the difference between const and static readonly?
The value of a static readonly field is set at runtime; therefore, the value can be modified by the containing class. On the other hand, the value of a const field is set to a compile-time constant.

22.What is the difference between delegate and event?
An event offers more restricted access than a delegate. When an event is public, other classes are only able to add or remove handlers for that event: such classes cannot—necessarily—fire the event, locate all the handlers for it, or remove handlers of which they are unaware.


23.What is the difference between GetType() and typeof? ?
GetType() Operates on object
Typeof Operates on type

24.What is the difference between the out and ref parameter modifiers?
Both the out and ref modifiers can be applied to method arguments. And, both imply that the argument will be passed by reference—either as a reference to a value type variable or to a reference type variable. However, the out parameter enables passing in an uninitialized variable and guarantees that it will come back with set to a value.

Wednesday, January 27, 2010

Benefits of Stored Procedure

Benefits of Stored Procedures
Why should you use stored procedures?
Let's take a look at the key benefits of this technology:
Precompiled execution. SQL Server compiles each stored procedure once and then reutilizes the execution plan. This results in tremendous performance boosts when stored procedures are called repeatedly.
Reduced client/server traffic. If network bandwidth is a concern in your environment, you'll be happy to learn that stored procedures can reduce long
SQL queries to a single line that is transmitted over the wire.
Efficient reuse of code and programming abstraction.

Stored procedures can be used by multiple users and client programs. If you utilize them in a planned manner, you'll find the development cycle takes less time.
Enhanced security controls. You can grant users permission to execute a stored procedure independently of underlying
table permissions.

Delloite interview questions .net

Difference between datareader and Dataset
Difference between ADO.net and ADO
Page Life cycle
WCF Advantages
Ho do you create paging
Do paging have performance over head
What are master pages
What is Clusterd index
Differnce between primary and unique key
How do you trace information of non web components
Is Trace.axd is a page?
How do you declare a global variable?

Wipro Interview questions 2010

  1. What is assembly
  2. What are authentications ? (Mention IIS and .net authentications)
  3. What is singleton class
  4. What are access modifiers explain
  5. Public,private,protected,Protected internal
  6. What is shared assemblies
  7. What is versioning
  8. Difference between ASP and ASP.net
  9. Difference between WebServices and WCF
  10. What is use of Webservice when you have DCOM
  11. How do you retrieve hierarchical data from database
  12. What is static class
  13. difference between abstract class and static class
  14. difference between interface and abstract class
  15. Use of Interface and delegates
  16. How do you handle webservice event in the page
  17. Page Life cycle
  18. Application Life cycle
  19. Session Modes
  20. Five Modes of Trace Switches.

Monday, January 25, 2010

Advantages of using WCF over Web Services

WCF Supports Multiple Bindings like http,tcp,MSMQ etc where as web services uses only http
WCF can maintain transaction like com+ .
It can mainitain state .
It can be hosted on IIS,Selfhosting,Windows Servies(Windows Application Service) .
The development of webservice with ASP.net relies on defining data and relies on the XMLSerializer to transform datato or from a service.
Key Issues of XML Serailizer to serialize .net Types with XML.
-Only Public fields and Properties of .net types can be translated to XML
-Only the classes which implement IEnumerable Interface can be translated to XML.
-Classes implementing IDictionary Interface such as Hash table cannot be serialized.

WCF Uses DataContractAttribute and DataMember Attribute to Translate .net types to XMl.
-DataContract Attribute can be used for classes and structures-DataMember Attribute to Field or Property
Diference between DataContractSerailizer and XML Serializer is
-DCS has better performance over XML Serialization
-XML Serialization doesn't indicate which field or property of the type is serialized, DCS Explicitly shows which field or property is serialized
-DCS can serialize classes implementing IDictionary interface(Hash Table)

Exception Handling
In ASP.NET Web services, Unhandled exceptions are returned to the client as SOAP faults.
In WCF Services, unhandled exceptions are not returned to clients as SOAP faults. A configuration setting is provided to have the unhandled exceptions returned to clients for the purpose of debugging.