Blog Home  Home Feed your aggregator (RSS 2.0)  
Software Code Help blogs
newtelligence powered
 
 Thursday, November 06, 2008

1. In the assembly that implements the type(Console), look up the method being called in the metadata.
2. From the metadata, get the IL from this method and verify it.
3. Allocate a block of memory.
4. Compile the IL into native CPU instructions: the native code is saved in the memory allocated in step#3.
5. Modify the method's entry in the Type's table so that it now points to the memory block allocated in Step#3.
6. Jump to the native code contained inside the memory block.

Thursday, November 06, 2008 5:25:33 AM (GMT Standard Time, UTC+00:00)  #    Comments [0]   C#  | 

Declare @Var1 nvarchar(800)

 

Set @Var1=’’

 

Select @Var1 = @Var1 + ‘,’ + Field1 from Table1

 

Select @Var1

Thursday, November 06, 2008 4:56:38 AM (GMT Standard Time, UTC+00:00)  #    Comments [0]   SQL  | 
 Friday, August 01, 2008

Virtual method has an implementation & provide the derived class with the option of overriding it.

 

Abstract method does not provide an implementation & forces the derived class to override the method.

Friday, August 01, 2008 11:02:21 AM (GMT Standard Time, UTC+00:00)  #    Comments [0]   Interview Question .NET  | 

Windows Authentication (via Active Directory) and SQL Server authentication (via Microsoft SQL Server username and password).

Windows Authentication is trusted because the username and password are checked with the Active Directory,

 

the SQL Server authentication is untrusted, since SQL Server is the only verifier participating in the transaction.

Friday, August 01, 2008 10:53:44 AM (GMT Standard Time, UTC+00:00)  #    Comments [0]   SQL  | 

1. Positive test cases (correct data, correct output).


2. Negative test cases (broken or missing data, proper handling).


3. Exception test cases (exceptions are thrown and caught properly).

Friday, August 01, 2008 10:50:06 AM (GMT Standard Time, UTC+00:00)  #    Comments [0]   Interview Question .NET  | 

System.Diagnostics.Process objDocProcess = new System.Diagnostics.Process();

objDocProcess.EnableRaisingEvents = false;

objDocProcess.StartInfo.FileName = @"C:\Excel.xls";

objDocProcess.Start();

Friday, August 01, 2008 9:48:11 AM (GMT Standard Time, UTC+00:00)  #    Comments [0]   Interview Question .NET  | 

A string is a sequential collection of Unicode characters that is used to represent text. At the other hand the string builder is sealed class(Cannot be inherited)it represents a mutable string of characters.

 

String is mutable that means that it can't be modified once created, to modify a given string by appending new characters or so the CLR destroy the first string instance and create a new string one and this costs in terms of memory and time process.

 

 Using the string builder, you create a mutable object that recieves modification without having to be destroyed and reinstanciated for each modifiaction

Friday, August 01, 2008 6:10:47 AM (GMT Standard Time, UTC+00:00)  #    Comments [0]   Interview Question .NET  | 
 Thursday, July 31, 2008

Poly means many and morph means form. Thus, polymorphism refers to being able to use many forms of a type without regard to the details.

Polymorphism have 2 types :

1. Compile time also called overloading have 3 types.

·         Constructor overloading (i.e., with same constructor name and different no of arguments or different datat types or both )

·         Function overloading (i.e., with same function name and different no of arguments or different data types or both)

·         operator overloading: example : Variable++;

2 Run time

·         It is achieved by overriding parent class method:

Thursday, July 31, 2008 2:05:28 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]   Interview Question .NET  | 

1. OnInit (Init)  -- Inializes all Child controls on the Page

2. LoadControlState  -- Loads the Control State 

3. LoadViewState -- Loads the View State

4. LoadPostData -- Control properties are set according to the received form data

5. Load -- Actions can be performed on the controls as all the pre-activities are complete by this time

6. RaisePostDataChangedEvent -- This event is raised if data has been changed in previous and Current Postbacks.

7. RaisePostBackEvent -- This event handles the user action that caused the Postback.

8. PreRender (OnPreRender) -- This event takes place between postback and saving viewstate. Till this stage changes will be saved to the control.

9. SaveControlState -- Self Explanatory

10. SaveViewState -- Self Explanatory

11. Render -- Generates artifacts at Client side (HTML,DHTML,Scripts) to properly display controls

12. Dispose -- Releases unmanaged Resource ( Database connections, file handles)

13. Unload -- Releases managed Resources ( Instances created by CLR)

Thursday, July 31, 2008 1:47:47 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]   Interview Question ASP.NET  | 

The XmlSerializer can be used when you need the data in the object to be stored in an XML Format. However, this serialize has the limitation that it can serialize only the public fields of an object.

The SoapFormatter is ideal in scenarios where you need interoperability. This is ideal in applications spanning heterogeneous environments.

The BinaryFormatter generates a very compact stream when an object is serialized as compared to the other two techniques and hence is useful when data needs to travel electronically across the wire. This is appropriate when the applications do not involve heterogeneous environments.

Thursday, July 31, 2008 1:43:06 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]   Interview Question .NET  | 

Serialization is the process of saving the state of an object by converting it to a stream of bytes. The object can then be persisted to file, database, or even memory. The reverse process of serialization is known as deserialization

 

This classification arises from the format in which the data in the object is persisted. Each of the serialization techniques mentioned have different capabilities and each excel in specific scenarios. The XML serialization technique can convert only the public properties and fields of an object into an XML format. The XML serialization is also known as shallow serialization.

This inability of the XMLSerializer to serialize the private fields of an object is overcome by the SOAP and binary serialization techniques. In the binary and SOAP serialization techniques, the state of the entire object is serialized into a stream of bytes. In cases where the object contains a reference to other objects, even those are serialized. This type of serialization is known as deep serialization.

Thursday, July 31, 2008 1:40:04 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]   Interview Question .NET  | 
  • An abstract class may contain complete or incomplete methods. Interfaces can contain only the signature of a method but no body. Thus an abstract class can implement methods but an interface can not implement methods.

 

  • An abstract class can contain fields, constructors, or destructors and implement properties. An interface can not contain fields, constructors, or destructors and it has only the property's signature but no implementation.

 

  • An abstract class cannot support multiple inheritances, but an interface can support multiple inheritances. Thus a class may inherit several interfaces but only one abstract class.

 

  • A class implementing an interface has to implement all the methods of the interface, but the same is not required in the case of an abstract Class.

 

  • Various access modifiers such as abstract, protected, internal, public, virtual, etc. are useful in abstract Classes but not in interfaces.
Thursday, July 31, 2008 12:28:18 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]   Interview Question .NET  | 
 Tuesday, July 01, 2008

You bet. Just call SetNoStore on the HttpCachePolicy object exposed through the Response object's Cache property, as demonstrated here:

 

 

<%@ Page Language="C#" %>
<html>
<body>
<%
Response.Cache.SetNoStore ();
Response.Write (DateTime.Now.ToLongTimeString ());
%>
</body>
</
html>

 

 

SetNoStore works by returning a Cache-Control: private, no-store header in the HTTP response. In this example, it prevents caching of a Web page that shows the current time.

Tuesday, July 01, 2008 11:24:24 AM (GMT Standard Time, UTC+00:00)  #    Comments [0]   Interview Question ASP.NET  | 

Most browsers recognize the following META tag as a signal to automatically refresh the page every nn seconds:

 

<meta http-equiv="Refresh" content="nn">

Here's an ASPX file that displays the current time of day. Once displayed, it automatically refreshes every 5 seconds:

 

<% Page Language="C#" %>
<meta http-equiv="Refresh" content="5">
<
html>
<body>
<%
Response.Write (DateTime.Now.ToLongTimeString ());
%>
</body>
</
html>

Tuesday, July 01, 2008 11:08:25 AM (GMT Standard Time, UTC+00:00)  #    Comments [0]   Interview Question ASP.NET  | 

Use the HtmlInputFile class, which you can declare an instance of with an <input type="file" runat="server"/> tag. The following example is a complete ASPX file that lets a user upload an image file and a comment descibing the image. The Upload_Click method writes the image and the comment to a table named Pictures in a SQL Server database named MyPictures.

<form id="Form2" enctype="multipart/form-data" runat="server">
<table>
<tr>
<td>File name</td>
<td><input type="file" id="Upload" runat="server" /></td>
</tr>
<tr>
<td>Comment</td>
<td><asp:TextBox ID="Comment" RunAt="server" /></td>
</tr>
<tr>
<td></td>
<td><asp:Button Text="Upload" OnClick="Upload_Click(" RunAt="server" /></td>
</tr>
</table>
</
form>

protected void Upload_Click(object sender, EventArgs e)
{
// Create a byte[] from the input file

int len = Upload.PostedFile.ContentLength;

byte[] pic = new byte[len];

Upload.PostedFile.InputStream.Read(pic, 0, len);

// Insert the image and comment into the database

SqlConnection connection = new SqlConnection("server=localhost;database=mypictures;uid=sa;pwd=");

try

{

connection.Open();

SqlCommand cmd = new SqlCommand("insert into Pictures " + "(Picture, Comment) values (@pic, @text)", connection);

cmd.Parameters.Add("@pic", pic);

cmd.Parameters.Add("@text", Comment.Text);

cmd.ExecuteNonQuery();

}

finally{
connection.Close();
}
}

Tuesday, July 01, 2008 11:02:22 AM (GMT Standard Time, UTC+00:00)  #    Comments [0]   Interview Question ASP.NET  | 
 Monday, June 30, 2008

A Simple Factory pattern is one that returns an instance of one of several possible classes, depending on the data provided to it. Usually all of the classes it returns have a common parent class and common methods, but each of them performs a task differently and is optimized for different kinds of data.

 

 

public abstract class Travel

{

    public abstract decimal GetPrice();

 

    public enum Types

    {

        Air, Hotel, Car

    }

    /// <summary>

    /// This class return value using factory

    /// </summary>

    /// <param name="t"></param>

    /// <returns></returns>

    public static Travel TravelFactory(Types t)

    {

        switch (t)

        {

            case Types.Air:

                return new Air();

 

            case Types.Hotel:

                return new Hotel();

 

            case Types.Car:

                return new Car();

 

        }

 

        throw new System.NotSupportedException("The Travel type " + t.ToString() + " is not recognized.");

    }

}

public class Air : Travel

{

    private decimal m_Price = 23.5M;

    public override decimal GetPrice() { return m_Price; }

}

 

public class Hotel : Travel

{

    private decimal m_Price = 11.5M;

    public override decimal GetPrice() { return m_Price; }

}

 

public class Car : Travel

{

    private decimal m_Price = 16.5M;

    public override decimal GetPrice() { return m_Price; }

}

 

// you can use factory using this code

...

Console.WriteLine( Travel.TravelFactory(Travel.Types.Air).GetPrice().ToString() );

...

Monday, June 30, 2008 5:29:52 AM (GMT Standard Time, UTC+00:00)  #    Comments [0]   C#  | 
 Thursday, June 26, 2008

The ASP.NET configuration section schema contains elements that control how ASP.NET Web applications behave. Our default configuration of web application is set in the Machine.config file that are located in this path c:\Windows\Microsoft.NET\Framework\versionNumber\CONFIG\Machine.config. The setting inside the machine.config file is applied to all web application installed on this System. If you want to change configuration setting for your particular application, Then we create web.config file inside our web application.

Here we specifies the root element for the ASP.NET configuration section. Contains configuration elements that configure ASP.NET Web applications and control how the applications behave.

<system.web>
   <authentication>
   <authorization>
   <browserCaps>
   <clientTarget>
   <compilation>
   <customErrors>
   <globalization>
   <httpHandlers>
   <httpModules>
   <httpRuntime>
   <identity>
   <machineKey>
   <pages>
   <processModel>
   <securityPolicy>      <serviceDescriptionFormatExtensionTypes>    <sessionState>
   <trace>
   <trust>
   <webServices>
 </system.web>

 
Authentication:- For setting our web application authentication inside <Authentication> tag. There are four different type of authentication “None”, “Windows”, “Forms”, “Passport”.
If you do not require any authentication, then use “None” inside mode
.
       <authentication mode="None"/>
Basically we are using Windows authentication as a default authentication. This authentication is handled by Internet Information Server(IIS). This provider uses IIS to perform the authentication and then passes the authenticated identity to your code.
       <authentication mode="Windows"/>

IIS gives you a choice for four different authentication methods: Anonymous, basic, digest, and windows integrated

Internet Information Server(IIS)

If user select anonymous authentication, IIS doesn’t perform any authentication on that web application.

If user select basic authentication, users must provide a windows username and password to connect. How ever this information is sent over the network in clear text, which makes basic authentication very much insecure over the internet.

If user select digest authentication, users must still provide a windows user name and password to connect. This information requires that all users be running Internet Explorer 5 or later and that windows account to stored in active directory.

If you select windows integrated authentication, passwords never cross the network. Users must still have a username and password, but the application uses either the Kerberos or challenge/response protocols authenticate the user.

Forms authentication uses web application forms to collect the user credential and on the basis of his credential, it takes action on web application

    <