Friday, October 12, 2007
Thursday, October 11, 2007
Difference between Class and Structure
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
Thursday, October 4, 2007
Attributes in .NET
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
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
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
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
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
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
What is Generics
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
// Declare a list of type string
GenericList
// Declare a list of type ExampleClass
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
{
return item;
}
Example
// This method will swap any two items.
// as specified by the type parameter
static void Swap
{
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
Example:-
where T : struct The type parameter
where T : class The type parameter
// Contained items must have a default ctor.
public class MyGenericClass
{...}
// Contained items must be a class implementing IDrawable
// and support a default ctor.
public class MyGenericClass
{...}
// MyGenericClass derives from MyBase and implements ISomeInterface,
// while the contained items must be structures.
public class MyGenericClass
{...}
(http://en.csharp-online.net/Understanding_Generics%E2%80%94Constraining_Type_Parameters_Using_where)
Session Management Techniques
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
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()
....
}
Basic functionality of a Garbage Collecter
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().
Wednesday, October 3, 2007
Difference between Response.Redirect and Server.Transfer
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?
DIfference between WebUserControl and CustomControl
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
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
Components and Assemblies
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
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
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
Life Cycle of a ASP.NET web page
http://www.geekinterview.com/question_details/22673
The important events in a PageLifecycle are below.
What is WebFarm and 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.