Sunday, September 30, 2007
Describe the role of inetinfo.exe, aspnet_isapi.dll andaspnet_wp.exe in the page loading process
inetinfo.exe is theMicrosoft IIS server running, handling ASP.NET requests among other things.When an ASP.NET request is received (usually a file with .aspx extension), the ISAPI filter aspnet_isapi.dll takes care of it by passing the request tothe actual worker process aspnet_wp.exe.
Does C# support properties of array types?
Yes. Here's a simple example:
using System;
class Class1
{
private string[] MyField;
public string[] MyProperty
{
get { return MyField; }
set { MyField = value; }
}
}
class MainClass
{
public static int Main(string[] args)
{
Class1 c = new Class1();
string[] arr = new string[] {"apple", "banana"};
c.MyProperty = arr;
Console.WriteLine(c.MyProperty[0]); // "apple"
return 0;
}
}
using System;
class Class1
{
private string[] MyField;
public string[] MyProperty
{
get { return MyField; }
set { MyField = value; }
}
}
class MainClass
{
public static int Main(string[] args)
{
Class1 c = new Class1();
string[] arr = new string[] {"apple", "banana"};
c.MyProperty = arr;
Console.WriteLine(c.MyProperty[0]); // "apple"
return 0;
}
}
Example of a Delegate.
Sample Program using Delegate :
public delegate double Delegate_Prod(int a,int b);
class Class1{static double fn_Prodvalues(int val1,int val2)
{
return val1*val2;
}
static void Main(string[] args)
{
//Creating the Delegate InstanceDelegate_Prod delObj = new Delegate_Prod(fn_Prodvalues);
Console.Write("Please Enter Values");
int v1 = Int32.Parse(Console.ReadLine());int v2 = Int32.Parse(Console.ReadLine());
//use a delegate for processing
double res = delObj(v1,v2);Console.WriteLine ("Result :"+res);Console.ReadLine();
}
}
Explanation:
Here I have used a small program which demonstrates the use of delegate.
The delegate "Delegate_Prod" is declared with double return type and which accepts only two integer parameters.
Inside the Class the method named fn_Prodvalues is defined with double return type and two integer parameters.(The delegate and method is having the same signature and parameters type)
Inside the Main method the delegate instance is created and the function name is passed to thedelegate instance as following.
Delegate_Prod delObj = new Delegate_Prod(fn_Prodvalues);
After this we are accepting the two values from the user and passing those values to the delegate as we do using method .
delObj(v1,v2);
Here delegate object encapsulates the method functionalities and return the result as we specifiedin the method.
public delegate double Delegate_Prod(int a,int b);
class Class1{static double fn_Prodvalues(int val1,int val2)
{
return val1*val2;
}
static void Main(string[] args)
{
//Creating the Delegate InstanceDelegate_Prod delObj = new Delegate_Prod(fn_Prodvalues);
Console.Write("Please Enter Values");
int v1 = Int32.Parse(Console.ReadLine());int v2 = Int32.Parse(Console.ReadLine());
//use a delegate for processing
double res = delObj(v1,v2);Console.WriteLine ("Result :"+res);Console.ReadLine();
}
}
Explanation:
Here I have used a small program which demonstrates the use of delegate.
The delegate "Delegate_Prod" is declared with double return type and which accepts only two integer parameters.
Inside the Class the method named fn_Prodvalues is defined with double return type and two integer parameters.(The delegate and method is having the same signature and parameters type)
Inside the Main method the delegate instance is created and the function name is passed to thedelegate instance as following.
Delegate_Prod delObj = new Delegate_Prod(fn_Prodvalues);
After this we are accepting the two values from the user and passing those values to the delegate as we do using method .
delObj(v1,v2);
Here delegate object encapsulates the method functionalities and return the result as we specifiedin the method.
Delegate
- Delegate is type which holds the method(s) reference in an object.it is also reffered as a type safe function pointers
- Advantages:.Encapsulating the method's call from caller, Effective use of Delegate improves the performance of application..used to call a method asynchronously
Declaration:
public delegate type_of_delegate delegate_name()
Example : public delegate int mydelegate(int delvar1,int delvar2)
Note:.you can use delegate without parameter or with parameter list.you should follow the same syntax as in the method (if you are reffering the method with two int parameters and int return type the delegate which you are declaring should be the same format.This is how it is reffered as type safe function pointer
Delegates are functional pointers.In C#, a delegate is a data structure that refers to either a static method, or an object and an instance method of its class. When you initialize a delegate, you initialize it with either a static method, or a class instance and an instance method. (
http://www.yoda.arachsys.com/csharp/csharp2/delegates.html)
Example of DllImport
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);
}
}
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);
}
}
Usind Dll Import
1. You need to add reference to System.Runtime.InteropServices; for this
2. All methods marked with the DllImport attribute must be marked as public static extern
Extern:-
Use the extern modifier in a method declaration to indicate that the method is implemented externally. A common use of the extern modifier is with the DllImport attribute.
2. All methods marked with the DllImport attribute must be marked as public static extern
Extern:-
Use the extern modifier in a method declaration to indicate that the method is implemented externally. A common use of the extern modifier is with the DllImport attribute.
How to explicit fall through for case blocks
The code below does the functionality where you can have a explicit fall through case blocks.
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;
}
}
}
Note:-Fall through means if you didn't write any statement in case 0, control automatically go to next case, which is not supported by c#, and we need to use goto statement to send control to next case
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;
}
}
}
Note:-Fall through means if you didn't write any statement in case 0, control automatically go to next case, which is not supported by c#, and we need to use goto statement to send control to next case
Saturday, September 29, 2007
CLS
Common Language Specification
- It is a set of rules, that define a subset of common types and programming constructs that all .NET programming languages can agree on.
- If no CLSCompliantAttribute is applied to a program element, then by default:
The assembly is not CLS-compliant.
The type is CLS-compliant only if its enclosing type or assembly is CLS-compliant.
The member of a type is CLS-compliant only if the type is CLS-compliant
Examples:-
- Jagged arrays — that is, arrays of arrays — are CLS-compliant. In the .NET Framework version 1.0, the C# compiler mistakenly reports that they are not.
- Enumerations must be of type Int16, Int32, or Int64. Enumerations of other types are not compliant.
- Example of non-CLS compliance:- For instance, unsigned types are supported by C# and MC++ but not by VB.NET (except for 'Byte', which is mapped on .NET's 'Byte' and takes values from 0 t o255). So, any public or protected member of a C# class that has an unsigned type or takes as parameter an unsigned is not CLS compliant.
CTS
Common Type System
- Fully describes, all possible datatypes and programming constructs supported by the runtime.
- It specifies, how the entities can interact with each other and details how they are represented in the .NET Metadata format.
CLR
CLR is Common Language Runtime.
- Runtime Layer is properly referred to as the CLR.
- Primary role of CLR is to locate, load and manage .NET types.(Responsible for Automatic memory Management, CTS, Lifecycle monitoring, Language integration, type safety.)
What is MS.NET
- .NET is Microsoft's platform independent Development Environment, within which using the .NET supported languages you can develop applications, components, and data technologies.
- .NET can be simply understood as a new runtime environment and a common base class library from programmers view.
Subscribe to:
Comments (Atom)