May 24, 2010

Indexers in C#

- used to treat an object as an array.
- syntax

this [argument list]
{

get
{

// your get block code

}

set
{

// your set block code

}

}

- Example

using System;



namespace Indexer_example1

{

class Program

{

class IndexerClass

{

private string[] names = new string[10];



public string this[int i]

{

get

{

return names[i];

}

set

{

names[i] = value;

}

}

}



static void Main(string[] args)

{

IndexerClass Team = new IndexerClass();

Team[0] = "Rocky";

Team[1] = "Teena";

Team[2] = "Ana";

Team[3] = "Victoria";

Team[4] = "Yani";

Team[5] = "Mary";

Team[6] = "Gomes";

Team[7] = "Arnold";

Team[8] = "Mike";

Team[9] = "Peter";



for (int i = 0; i < 10; i++)

{

Console.WriteLine(Team[i]);

}

Console.ReadKey();

}

}

}

FAQ's on Constructors

1. Is the Constructor mandatory for the class ?

Yes, It is mandatory to have the constructor in the class and that too should be accessible for the object i.e., it should have a proper access modifier. Say for example we have the private constructor in the class then it is of no use as it cannot be accessed by the object, so practically it is no available for the object. In such conditions it will raise an error.

2. What if I do not write the constructor ?

In such case the compiler will try to supply the no parameter constructor for your class behind the scene. Compiler will attempt this only if you do not write the constructor for the class. If you provide any constructor ( with or without parameters), then compiler will not make any such attempt.

3. What if I have the constructor public myDerivedClass() but not the public myBaseClass() ?

It will raise an error. If either the no parameter constructor is absent or it is in-accessible ( say it is private ), it will raise an error. You will have to take the precaution here.

4. Can we access static members from the non-static ( normal ) constructors ?

Yes, We can. There is no such restriction on non-static constructors. But there is one on static constructors that it can access only static members.

May 12, 2010

Windows Workflow Foundation(WWF) basics

Windows Workflow Foundation(WWF) basics

 

I found good article on WWF here. Very useful….Happy Learning…

 

http://www.dotnetfunda.com/articles/article155.aspx

May 7, 2010

Dotnet Framework Basics

 

Microsoft .NET Framework

========================

 

.NET Framework = Base class Library(BCL) + CLR

 

CLR - provides Memory management, Thread management, Exception handling, Garbage collection, Security.

BCL - user interface, data access, database connectivity, cryptography, web application development, numeric algorithms, and       network communications.

 

Source Code(C#) -------------> MSIL (or) CIL ----------------------------> Native Code

                C# compiler                       CLR using JIT compiler

 

Types of JIT compiler

---------------------

Pre-JIT

Econo-JIT

Normal-JIT

 

Pre-JIT :- Pre-JIT compiles complete source code into native code in a single compilation cycle. This is done at the time of deployment of the application.

Econo-JIT :- Econo-JIT compiles only those methods that are called at runtime.However, these compiled methods are removed when they are not required.

Normal-JIT(default) :- Normal-JIT compiles only those methods that are called at runtime.These methods are compiled the first time they are called, and then they are stored in cache. When the same methods are called again, the compiled code from cache is used for execution.

 

CTS & CLS

----------

- CLS is a subset of CTS

- Common Type System (CTS) describes how types are declared, used and managed in the runtime and facilitates cross-language integration, type safety, and high performance code execution.

- Common Language Specification (CLS) is nothing but guidelines that a language to follow so that it can communicate with other .NET languages in a seamless manner

 

Assemblies

----------

- an assembly is a partially compiled code library for use in deployment, versioning and security

- an assembly is an EXE or DLL

- Private and Shared assemblies

- Private assemblies are stored along with the applicaton folder

- Share assemblies are stored in GAC.

- ILDASM is used to view assembly. It shows manifest and metadata.

- Manifest contains version, scope, security, references to resources and classes.

- Metadata is data about data and it contains information about classes, structs, interfaces, namespaces, etc.

- To create strong name sn -k "c:\temp.snk" to uniquely identify the assembly in GAC.

- Delay Signing : To avoid showing the strong names to developer during development

                [assembly:AssemblyKeyFileAttribute("myKey.snk")]

                [assembly:AssemblyDelaySignAttribute(true)]

- Ex:

                using System;

                namespace SURComponents

                {

                                public class Sample

                                {

                                                public string GetData()

                                                {

                                return "hello world";

                                                }

                                }

                }

In the above example SURComponents assembly is created. We can import this assembly and create an object for the class Sample to use the method GetData().

 

Garbage Collector

-----------------

- Three generations Generation0, Generation1, Generation2.

- Gen0 contains all the newly created objects and it is in the top of heap. Gen1 contains all the living objects from Gen0   and in the middle of heap. Gen2 contains all the living objects from Gen1 is in the bottom of heap.

- GC is able to collect the garbage in two ways: full collections (searching the entire managed heap for dead objects) and   partial collections (searching only a single generation zone).

 

 

Access to COM components is provided in the System.Runtime.InteropServices and System.EnterpriseServices namespaces of the framework

 

Mar 10, 2010

Difference between stored procedures and functions ?

1>Procedure can return zero or n values whereas function can return one value which is mandatory.

2>Procedures can have input,output parameters for it whereas functions can have only input parameters.

3>Procedure allow select as well as DML statement in it whereas function allow only select statement in it.

4>Functions can be called from procedure whereas procedures cannot be called from function.

5>Exception can be handled by try-catch block in a procedure whereas try-catch block cannot be used in a function.

6>We can go for transaction management in procedure whereas we can't go in function.

7>Procedures can not be utilized in a select statement whereas function can be embedded in a select statement.

Mar 9, 2010

COM Basics - Important Points

COM
===

IUNKNOWN

1)Base interface of COM. Every interface directly or indirectly derived from this interface
2)Provides three methods AddRef, QueryInterface, Release
3)AddRef increments the reference count to the object
4)Release decrements the reference count to the object
5)QueryInterface obtains Pointer to the object.
6)QueryInterface returns E_NOINTERFACE if requested object was not found and also nullify its out parameter.

IDISPOSE

1)exposes objects, methods and properties to programming tools and other applications that support Automation.
2)The object's properties and methods can be accessed using IDispatch::GetIDsOfNames and IDispatch::Invoke.

CoCreateInstance and CoCreateInstanceEX

1)CocreateInstance is used to create object in local system and it allows only one object to create at a time.
2)CoCreateInstanceEx is used to create object in remote system and it allows to create multiple objects based on single CLSID

Aggregation

1)Is the mechanism in which outerobject exposes the methods of inner object
2)We can get a pointer to the inner interface, calling QueryInterface of the outer object with IID of the inner interface.

Moniker

1)An object that implements IMoniker interface.
2)provides information to uniquely identify a COM object.

OLE vs COM

1)OLE is build on top of COM
2)COM is a specification, while OLE is a particular implementation of this specification

COM vs DCOM

1)introduced several improvements for distributed environment, such as MULTI_QI (multiple QueryInterface()), security

contexts
2)DCOM demonstrated importance of surrogate process (you cannot run in-proc server on a remote machine).
3)DCOM introduced a load balancing
4)DCOM extends COM

Dual Interface

1) which supports both IDISPATCH and V-Table based interfaces
2)You may have two dual interfaces in one class. you cannot work with two dual interfaces at the same time.

Marshalling By Value

1) Instead of accessing an object remotely, it is possible to copy the static state of the object and create a new object with the same state information on the caller side.
2) not involve network round trips.

multi-threaded apartment (MTA) and Single-threaded apartment (STA)

1) In STA, all calls will be made by the same thread. In MTA, COM object can be accessed by many threads simultaneously
2) A process can have only one MTA, but many STAs

In-Proc means COM object that implemented as DLL and supposed to be hosted by a container. When you have to instantiate the in-proc object remotely, you may use DLLHost.exe application that was design specially for this purpose.

IDL

Interface Definition Language to describe COM interfaces

Is there a way to register in-proc server without regsvr32.exe?

Yes. Call DllRegisterServer() from the client. Do not forget to call DLLUnregisterServer() from the same client. You may also use Registrar object for the same purpose or use direct manipulation of the windows registry.

Classic ASP Basics - 1

global.asa
==========

application events
session events
object declarations
TypeLibrary declarations
#include directive

======================




You could reference the object "MyAd" from any page in the ASP application:

<%=MyAd.GetAdvertisement("/banners/adrot.txt")%>

========================

Calling stored procedure from ADO
=================================

Set cn = Server.CreateObject("ADODB.Connection")
Set cmd = Server.CreateObject("ADODB.Command")
cn.Open "data source name", "userid", "password"
Set cmd.ActiveConnection = cn
cmd.CommandText = "sp_test"
cmd.CommandType = adCmdStoredProc
' Ask the server about the parameters for the stored proc
cmd.Parameters.Refresh
' Assign a value to the 2nd parameter.
' Index of 0 represents first parameter.
cmd.Parameters(1) = 11
cmd.Execute
%>
Calling via method 1

ReturnValue = <% Response.Write cmd.Parameters(0) %>

Cursors types in ADO
====================

1) adOpenDynamic :- Additions, Changes and Deletions by other users will be visible
2) adOpenKeyset :- Only changes will be visible. Additions and Deletions are not visible.
3) adOpenStatic :- Additions, Changes and Deletions by other users are not visible. Used for disconnected recordset model.
4) adOpenForward-only :- Additions, Changes and Deletions by other users are not visible. To only scroll forward only.

Cursor Locations in ADO
=======================

adUseNone
adUseServer
adUseClient (read only)
adUseClientBatch

Cursor Lock types in ADO
=======================

adLockPessimistic - Locks the row once after any edits occur.
adLockOptimistic - Locks the row only when Update is called.
adLockBatchOptimistic - Allows Batch Updates.
adLockReadOnly - Read only. Cannot alter the data.

Disconnected Recordset
=======================

set con= server.createobject("ADODB.Connection")
set rs= server.createobject("ADODB.Recordset")
rs.CursorLocation=adUseClient
con.open sqlcon
rs.open sqlqry, con, adOpenStatic, adLockBatchOptimistic
Set oRS.ActiveConnection = Nothing
Set GetanotherRS = oRS

Clustered and nonclustered indexes
=================================

Clustered indexes contains actual data at leaf nodes
non clustered indexes contains row locators that point to actual data. 249 -> 999