Search This Blog

Thursday, December 27, 2012

Common Language Specification (CLS)

Common Language Specification is a set of base rules to which any language targeting the CLI should conform in order to interoperate with other CLS-compliant languages.

Common Language Specification (CLS) is a set of basic language features needed by many applications.

To fully interact with other objects regardless of the language they were implemented in, objects must expose to callers only those features that are common to all the languages they must interoperate with.

UInt32 Structure

UInt32 Structure represents a 32-bit unsigned integer.

The UInt32 type is not CLS-compliant.
The CLS-compliant alternative type is Int64.

HttpContext.Session ASP.NET

ASP.NET > HttpContext > Session

Gets the HttpSessionState object for the current HTTP request.

ASP.NET pages contain a default reference to the System.Web namespace you can reference the members of HttpContext on an .aspx page without the fully qualified class reference to HttpContext. For example, you can use just Session("USER").

Note: If you want to use the members of HttpResponse from an ASP.NET code-behind module, you must include a reference to the System.Web and also fully qualify the reference.

For example, in a code-behind page you must specify the full name:
 
HttpContext.Current.Session("USER").







Friday, December 21, 2012

Class with events VB NET

VB.NET > Class > WithEvents

WithEvents specifies that one or more declared member variables refer to an instance of a class that can raise events.

Example: class with events

 Public Class Export
        Public Event TimesUp()
        Public Sub New()
            Dim worker As New BackgroundWorker()
            AddHandler worker.DoWork, AddressOf DoWork
            AddHandler worker.RunWorkerCompleted, AddressOf bg_RunWorkerCompleted
            worker.RunWorkerAsync()
        End Sub
        Private Sub DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs)
            ' export stuff
            Thread.Sleep(5000)
        End Sub
        Private Sub bg_RunWorkerCompleted(ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs)
            MsgBox("Background worker completed", vbInformation, "Background worker")
            RaiseEvent TimesUp() 'Triggers an event declared at module level within a class, form, or document.
        End Sub
    End Class

    Dim WithEvents _Export As New Export
    Private Sub handleTimesUp() Handles _Export.TimesUp
        MsgBox("TimesUp Event Raised and Handled")
    End Sub

 





BackgroundWorker VB.NET

VB.NET > BackgroundWorker

Executes an operation on a separate thread.

DoWork event occurs when RunWorkerAsync is called.
RunWorkerCompleted event occurs when the background operation has completed, has been canceled, or has raised an exception.

Example:

Imports System.ComponentModel
Imports System.Threading
Module Module1

  Public Sub backWork()
    Dim worker As New BackgroundWorker()
    AddHandler worker.DoWork, AddressOf DoWork
    AddHandler worker.RunWorkerCompleted, AddressOf bg_RunWorkerCompleted
    worker.RunWorkerAsync()
  End Sub

  Private Sub DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs)
    ' some work
    Thread.Sleep(5000)
  End Sub

  Private Sub bg_RunWorkerCompleted(ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs)
    MsgBox("Background worker completed", vbInformation, "Background worker")
  End Sub

End Module





Thursday, December 20, 2012

ArrayList Class C#

C# > Collections > ArrayList

Implements the IList interface using an array whose size is dynamically increased as required.

Example

using System;
using System.Collections;
public class SampleArrayList  {

public static void Main()
{
   ArrayList m_l = new ArrayList();
   m_l.Add("a");
   m_l.Add("b");
   m_l.Add("c");
   m_l.Add(1);
   Console.WriteLine(" Count: {0}", m_l.Count);
   Console.WriteLine(" Capacity: {0}", m_l.Capacity);
   Console.Write( " Elements:" );
   PrintElements(m_l);
  }
  public static void PrintElements(IEnumerable m_l)
 {
    System.Collections.IEnumerator _enum = m_l.GetEnumerator();
    while (_enum.MoveNext())
           Console.Write("\t {0}", _enum.Current);
    Console.ReadLine ();
 }
}






Array C#

C# > Types > Array

An array is a data structure that contains a number of variables called the elements of the array.
C# arrays are zero indexed.
All of the array elements must be of the same type.
Array elements can be of any type, including an array type.

Single-Dimensional Arrays

int[] m_i = new int[3];
string[] m_s = new string[5];
int[] m_i = new int[] { 1, 2, 3 }; // Array Initialization

Multidimensional Arrays

int[,] m_i = new int[3,2]; // two-dimensional array of 3 rows and two columns:
int[,,] m_i_1 = new int [5,1,2]; //  array of three dimensions, 5, 1, 2
int[,] myArray = new  int[,] {{1,2}, {3,4}, {5,6} }; // Array Initialization

Jagged Arrays

A jagged array is an array whose elements are arrays. The elements of a jagged array can be of different dimensions and sizes.

int[][] m_j = new int[2][];

m_j[0] = new int[2];
m_j[1] = new int[3];