Thursday, October 11, 2007

Difference between Class and Structure

1.structs derive from System.ValueType whereas classes derive from System.Object or one of its descendants. Of course, System.ValueType again derives from System.Object, but that's beside the point

2. Structs cannot derive from any other class/struct, nor can they be derived from. However, a struct can implement any number of interfaces. But when you treat Struct as a interface, it gets implicitly boxed.

Example:-

struct Foo : IFoo
{
int x;
}

and then: IFoo iFoo = new Foo();

an instance of Foo is created and boxed. All interface method calls then execute only on the boxed instance.

3. C# does not allow structs to have a default parameterless constructor( But CLR allows).

Example:-

struct Foo

{
int x;
public Foo(int x)// C# doesn't allow parameterless constructor

{
this.x = x;
}
}

class FooTester
{
[STAThread] static void Main(string[] args)
{
Foo f = new Foo();//though you are calling a parameterless constructor here, all it does is initialize the struct's fields to null/zero
}
}

Friday, October 5, 2007

What is a Satellite Assembly

Satellite assemblies contain resource files corresponding to a locale (Culture + Language) and these assemblies are used in deploying an application globally for different languages.

Thursday, October 4, 2007

Attributes in .NET

Attributes are declarative tags in code that insert additional metadata into an assembly. There exist two types of attributes in the .NET Framework: Predefined attributes such as AssemblyVersion, which already exist and are accessed through the Runtime Classes; and custom attributes, which you write yourself by extending the System.Attribute class.

Attributes are part of metadata for a class.
Attributes are used to specify assembly information like key file name, or for specifying security related information. You can create new attributes for your specific needs or ideas.

What is WebService

web service is a software component that exposes itself through the open communication channels of the Internet. Applications running on remote machines, on potentially different platforms, can access these components in a language and platform-independent manner.A Web Service is a group of functions, packaged together for use in a common framework throughout a network.

WebSevice is a reusable software component (ClassLibraries) which exposes the businesslogic in them, platform independent, technology independent, language on which it is created, can be transported on HTTP (which is stateless) and provides the xml (Universal Accepted language which can be passed through firewalls) by exposing thruough SOAP (Simple Object Access Protocol) messages between the Caller and the component..

Webservice: Appropriate, when exposing the functionalitiss across differnt platforms(windows/Linux/Solaris..etc.,) or.NET to J2EE.


.NET Componet: Appropriate, when exposing the functionalitis within propritory O/S(.Net-.Net, or Java-Java platform)

What is Marshalling

Marshaling is the act of taking data from the environment you are in andexporting it to another environment. In the context of .NET, marhsalingrefers to moving data outside of the app-domain you are in, somewhere else.

When you work with unmanaged code, you are marshaling data from yourmanaged app-domain to the unmanaged realm. Also, when transferring databetween app-domains (to another application, on the same or anothermachine), you are also marshaling data from your app-domain, to anotherapp-domain.

Marshaling is serializingor transforming types over the wire or some boundary. COM had marshalingwhen you went out of one apartment into a non-compatible apartment or acrossthe wire to another machine. When dealing with COM Interop, .NET usesInterop Marshaling between COM data types and .NET CLR types.

Unmanaged code is simply all code pre .NET. It is all code NOT compiled tooperate under .NET's runtime, the CLR. Unmanaged code is code compiled andlinked natively and has no knowledge of the CLR. Unmanaged code can benative C++ with pointers, or C, or VB 6, or Delphi, etc. It is everythingnot managed by the CLR. In the CLR, code is compiled into IL + metadata intoassemblies and then those assemblies are JITed into assembly languageinstructions while called. It is the metadata throughout that allows managedcode to be managed, managed by the CLR.


From the perspective of a .NET developer, managed code does in fact equal..NET code, and unmanaged code is all code that does not run under the CLR.However, Java bytecode is often referred to as "managed code" as well. Bythis more generic definition, managed code is any code that is run in amanaged environment that controls security access and access to resources.That managed environment might be .NET's Common Language Runtime, Java'sbytecode interpreter, or something else. It is not enough for the code torequire a supporting runtime; VB6 or FoxPro executables, for example, arenot "managed" in this sense. A support library full of routines ispassively called by such code; but unlike a suport library, a mangedenvironment may refuse application an request if it violates securityprotection levels or accesses forbidden resources. In order to be able todetermine whether or not to honor requests, the application code must beself-describing; hence the other requirement to call an executionenvironment "managed."

Mutable and Immutable Class

Immutable type are types whose instance data, fields and properties, does not change after the instance is created. Most value types are immutable, but the mutable type are A type whose instance data, fields and properties, can be changed after the instance is created. Most Reference Types are mutable. Shortly we can say as: When you have a reference to an instance of an object, the contents of that instance can be altered for Mutable objects and When you have a reference to an instance of an object, the contents of that instance cannot be altered for Immutable objects.



String is a immutable class. It is advised if the value of the stringvaraible is going to change from time to time then we use a StringBuilder which is a mutable class.
Hence when u change the value of as instance of string object (instance of immutable class) then new memory is created and value is stored in the new memory, where as if you assign a new value to an instance of StringBuilder class then value is changed in the same memory and this gives a performance improvement.
So in case if the string is frequently changed in the code at run time, it is advisable to use mutable objectes.

What is Marshalling

Marshaling performs the necessary conversions in data formats between managed and unmanaged code. CLR allows managed code to interoperate with unmanaged code usining COM Marshaler(Component of CLR)

If fake copy of the server object that resides as really act as server. this marshall object is communicated to the server real server object and the client object. This process is known as marshelling

The .NET Framework offers several methods for customizing the presentation of native .NET and COM object types. One such technique, custom marshaling, refers to the notion of specializing object type presentations. There are times, like when a legacy COM component needs to implement a new interface or when you need to make calls across process or machine boundaries, when custom marshaling saves the day. Elements of COM Interop permit the customizing of COM types while .NET Remoting offers the developer the ability to tailor native .NET types. This article examines these techniques.

Difference between Debug.Trace and Trace.Write

What is the difference between Trace and Debug?
Trace and Debug - There are two main classes that deal with tracing - Debug and Trace. They both work in a similar way - the difference is that tracing from the Debug class only works in builds that have the DEBUG symbol defined, whereas tracing from the Trace class only works in builds that have the TRACE symbol defined. Typically this means that you should use System.Diagnostics.Trace.WriteLine for tracing that you want to work in debug and release builds, and System.Diagnostics.Debug.WriteLine for tracing that you want to work only in debug builds.




For more information see this article

http://www.dotnetuncle.com/Difference/56_trace_debug.aspx

Using QueryString

What is Generics

Generic classes and methods combine reusability, type safety and efficiency in a way that their non-generic counterparts cannot. Generics are most commonly used with collections and the methods that operate on them. Version 2.0 of the .NET Framework class library provides a new namespace, System.Collections.Generic, which contains several new generic-based collection classes. It is recommended that all applications that target Version 2.0 use the new generic collection classes instead of the older non-generic counterparts such as ArrayList.

For moer details, see this article
http://msdn2.microsoft.com/en-us/library/512aeb7t(vs.80).aspx


C#
// Declare the generic class
public class GenericList
{
void Add(T input) { }
}
class TestGenericList
{
private class ExampleClass { }
static void Main()
{
// Declare a list of type int
GenericList list1 = new GenericList();
// Declare a list of type string
GenericList list2 = new GenericList();
// Declare a list of type ExampleClass
GenericList list3 = new GenericList();
}
}

MORE DETAILS



Generics introduce to the .NET Framework the concept of type parameters, which make it possible to design classes and methods that defer the specification of one or more types until the class or method is declared and instantiated by client code. For example, by using a generic type parameter T you can write a single class that other client code can use without incurring the cost or risk of runtime casts or boxing operations

Remember Boxing and unboxing when come across geenrics


create your own generic interfaces, classes, methods, events and delegates

The data type of the parameters can change with each use

Sample method using Generic DataType

protected GenType MyMethod(GenType item)
{
return item;
}

Example

// This method will swap any two items.
// as specified by the type parameter .
static void Swap(ref T a, ref T b)
{
Console.WriteLine("You sent the Swap() method a {0}",
typeof(T));
T temp;
temp = a;
a = b;
b = temp;
}



Generics provide a way for programmers to define “placeholders” (formally termed type parameters) for method arguments and type definitions, which are specified at the time of invoking the generic method or creating the generic type.


By convention, generic types specify their placeholders using uppercase letters. Although any letter (or word) will do, typically T is used to represent types, K is used for keys, and V is used for values.


.NET generics may be defined with optional constraints using the where keyword to address issues like Cannot convert type T to..given that the compiler does not yet know the value of the type parameter and cannot guarantee the cast would be legal
Example:-

where T : struct The type parameter must have System.ValueType in its chain of inheritance.
where T : class The type parameter must not have System.ValueType in its chain of inheritance (e.g., must be a reference type).


// Contained items must have a default ctor.
public class MyGenericClass where T : new()
{...}
// Contained items must be a class implementing IDrawable
// and support a default ctor.
public class MyGenericClass where T : class, IDrawable, new()
{...}
// MyGenericClass derives from MyBase and implements ISomeInterface,
// while the contained items must be structures.
public class MyGenericClass : MyBase, ISomeInterface where T : struct
{...}

(http://en.csharp-online.net/Understanding_Generics%E2%80%94Constraining_Type_Parameters_Using_where)

Session Management Techniques

1. In-Proc: the default provider.

2. Session Service: ASPNET_Session service. a diff service, runs outside IIS's service.
pros: in case of app recycle - the session remains the same; helpful when it's a web garden.
cons: cross process communication (performance)

3. Sql session provider: single point for sessions. remains on disk.

pros: a web farm solution; survives power failure;

cons: performance (disk i/o).

4. custom: build your own provider :-)

What is Sharepoint Portal

Share point portal in a enhancement of asp.net web parts. It is made for the rich user intractiveness. It provide you a customize platform where you can design your web portal within the seconds based on the templates. It is a part of microsoft concept for remove coding from web development.


Windows Sharepoint Services (WSS), together with Sharepoint Portal Server (SPS), has made a tremendous impact in the past few years. WSS and SPS have enabled organizations to set up powerful collaboration systems and portals that let users efficiently work together to create and consume information


If you are familiar with ASP.NET or Windows Forms development, you should also be familiar with UserControls. A Sharepoint WebPart is very similar to a UserControl with respect to how it is built. Developers can simply add ASP.NET controls into the WebPart and include some code for implementing the business logic into the controls in the WebPart. Then the WebPart can be deployed into a specified location in the portal server, granting all of the Sharepoint users immediate access to the new WebPart in their web pages.

Code snippet:-

public class MyWebPart:Microsoft.Sharepoint.WebPartPages.WebPart

{
...
protected override CreateChildControls()

....

}

How to explicitly release the Memory in .NET

Basic functionality of a Garbage Collecter

Garbage Collector in .Net Framework is used for Automatic Memory Management

i.e. it is collect all unused memory area and give to application. system.gc.collect() is a method for release the memory. But remember one think, it is only an request, i.e. we can't explicitly release the memory by using system.gc.collect().

Difference between Compiler and Interpretter

Wednesday, October 3, 2007

Difference between Response.Redirect and Server.Transfer

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 performs 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.

____

Server.Transfer() send the request to server
Response.Redirect() sends the request to Browser

So, If the Request is made for the location outside the Server, it fails. so you need to use Respons.Redirect().

what is the difference between serializable and marshalbyrefobject in remoting?

In .net Remoting if u want ur class to be participated in remoting it has to inherit from MarshalByRefObject class so that class definition can be passed by reference Where as [seraliazable] attribute is preceded before class that is can be seralized but this is used in conjuction with MarshalByValue class.Because when we pass by value then only we require this attribute

DIfference between WebUserControl and CustomControl

1. Both are used for Reusability.

2. Custom controls can be reused in any project or application by adding the control to the toolbox or storing as com component.User controls are used for that particular project.

Difference between Datalist and Repeater

The differences are

1. Repeater is generally used as a read-only forward-only control displaying data items one by one. DataList is used as a read-write control displaying one row of data at a time. Repeater is not used when editing is a requirement.

2. Repeater derives from Control while DataList derives from WebControl. As a result Repeater needs more programming to control the display, generate events etc. and is not used for complex purposes.

3. DataList is flexible in terms of number of data-rows which can be displayed per row. Repeater does not have this facility

.4. Repeater is the only control which allows html start tag to be placed in header item template and end tag to be placed in the footer item template. DataList does not allow this.5. Repeater has HeaderTemplate, FooterTemplate, ItemTemplate, AlternatingItemTemplate and SeparatorTemplate. DataList has all these 5 templates + SelectedItemTemplate and EditItemTemplate

What is Serialization?

Components and Assemblies

Components are packaged in assemblies. Assemblies are the reusable, versionable, self-describing building blocks of .NET applications. The simplest assembly is a single executable that contains all the information necessary for deployment and versioning.




For more details please have a look in to the following link.

http://msdn2.microsoft.com/en-us/library/01dx6zs7(vs.71).aspx

uploading and downloding the image in oracle database using asp.net

Contents are from the following link :-

http://www.geekinterview.com/question_details/28239

First way is store image in BYTEARRAY while checking UPLOAD CONTROL and hold that image in CACHE. And then store it (bytearray) in Database while clicking SAVE button.

2. Another way is to PUT that image on server by using UPLOAD.FileSave("PATH OF FILE") in an Binary array. The file will be saved in a folder on the server in JPG or any other form. And while saving it, image will have to be transfer from BinaryArray to Database. However if you do not want to make your database heavy becuase of the image, let it be stored on the server folder - just save the path of that file in the Database, which can be extracted while runtime of the application


3. To upload the image in to the Oracle: if you are using stored procedure then by using command instance object you and pass the image in Binary Format is Request.BinaryRead() and to display the image user the same method i.e. reponse.binarwrite()

How to create a permanent cookie

The permanent cookie is created the same way the normal cookie is created. To create a permanent cookie you have to specify a date in the future. Like,oHeader.AddCookie('userid',lcID,'/wconnect','NEVER') where NEVER is converted to a date in future.

HttpCookie l_objCookie = new HttpCookie("myCokie", "myValue");
l_objCookie.Expires = DateTime.MaxValue;
Response.Cookies.Add(l_objCookie);

Difference between Webservice and Remoting


ASP.NET Web Services

.NET Remoting

Protocol

Can be accessed only over HTTP

Can be accessed over any protocol (including TCP, HTTP, SMTP and so on)

State Management

Web services work in a stateless environment

Provide support for both stateful and stateless environments through Singleton and SingleCall objects

Type System

Web services support only the datatypes defined in the XSD type system, limiting the number of objects that can be serialized.

Using binary communication, .NET Remoting can provide support for rich type system

Interoperability

Web services support interoperability across platforms, and are ideal for heterogeneous environments.

.NET remoting requires the client be built using .NET, enforcing homogenous environment.

Reliability

Highly reliable due to the fact that Web services are always hosted in IIS

Can also take advantage of IIS for fault isolation. If IIS is not used, application needs to provide plumbing for ensuring the reliability of the application.

Extensibility

Provides extensibility by allowing us to intercept the SOAP messages during the serialization and deserialization stages.

Very extensible by allowing us to customize the different components of the .NET remoting framework.

Ease-of-Programming

Easy-to-create and deploy.

Complex to program.

Syntax for knowing IIS version

response.write(Request.ServerVariables("SERVER_SOFTWARE"))

Using Crystal Reports in ASP.NET

How to show graphs in ASP.NET?

Software Development Lifecycle

Life Cycle of a ASP.NET web page

Here are the events of ASP.NET WEb Application and Webpage. However, all this are not important and I have explained the important steps later in this post.

http://www.geekinterview.com/question_details/22673

The important events in a PageLifecycle are below.

Star

No Clouds can hide stars for a long time.

What is WebFarm and WebGarden

There is two or more than two server in webfarm method, and we also have a router in this technique, which is basically is used to route the a particular incoming request .Where as in case of a webgarden we have a one server having more than one processor.There are two techniques to implements webgarden 1. witout webgarden 2. with webgarden


A web farm is a multi-server scenario. So we may have a server in each state of US. If the load on one server is in excess then the other servers step in to bear the brunt. How they bear it is based on various models.

1. RoundRobin. (All servers share load equally)
2. NLB (economical)
3. HLB (expensive but can scale up to 8192 servers)
4. Hybrid (of 2 and 3)
.5. CLB (Component load balancer).


A web garden is a multi-processor setup. i.e., a single server (not like the multi server above).


How to implement webfarms in .Net:Go to web.config and Here for mode = you have 4 options.a) Say mode=inproc (non web farm but fast when you have very few customers).

b) Say mode=StateServer (for webfarm)

c) Say mode=SqlServer (for webfarm)

Whether to use option b or c depends on situation. StateServer is faster but SqlServer is more reliable and used for mission critical applications.



How to use webgardens in .Net:Go to web.config and webGarden="false"...>Change the false to true.

You have one more attribute that is related to webgarden in the same tag called cpuMask.

What is InProc

What is a WebPart