Thursday, April 26, 2012

Assembly



  • An assembly is a file that  is automatically generated by the compiler up on successful completion of  every .NET application.It can be either a dynamic link library or an executable file.
  • [Dynamic Link Library(DLL) - A DLL is a library that contains code and data that can be used by more than one program at the same time. For example, in Windows operating systems, the Comdlg32 DLL performs common dialog box related functions. Therefore, each program can use the functionality that is contained in this DLL to implement an Open dialog box. This helps promote code reuse and efficient memory usage.]
  • An assembly is generated only once for an application and up on each subsequent compilation the assembly gets updated



Monday, March 5, 2012

Configuration management

Configuration management

It refers to the adaptation of an application to a specific execution environment or user.The typical example of such configuration information is the connection string used to locate and connect to the application database.

StringBuilder Class

StringBuilder Class

The StringBuilder class is used for very fast string concatenation. If you use conventional string concatenation then it will run very slow because a string is held in an array. Each concatenation causes the array to increase its size and the memory has to be copied to a new location internally. This is very slow

Represents a mutable string of characters. This class cannot be inherited.
If we want to do a concatenation or any other operation to an existing string say,
string test="malayalam";
i want to add english to the string a .
test.append("english");

so now the string test becomes "malayalamenglish."But the old value in the string test="malayalam" get over writed.

String is immutable.

eg:
string test="malayalam";
test=malayalam+english
test=malayalmenglish..
But here the previous value wont get destroed.Because another memory location is created for the answer test=" malayalamenglish"


System Types and Collections

Programs, objects and methods

.NET is essentially a set of tools to build and execute computer programs.
A program is a set of instructions given to a computer that execute those instuctions automatically to manipulate some data.
.NET follows the object-oriented paradigm which means that the instructions and data are grouped around ‘’objects’’ that represent things or concepts. Objects that share the same instructions and manipulate the same kind of data are grouped into the same type.

Types are a way to classify the concepts or objects of a language.

System types: Types that are part of the .NET framework class library is called system types. Custom types: Types that will be constructed by the developer is called custom types.
eg:Writing object oriented programs can be seen as the process of defining one or more custom types.

Namespaces are a way to organize types so that they can be more easily found.
In the context of namespaces the System types are the types included in the System namespace or one of its sub-namespace .
Custom types (non system types) should use other namespaces.
There are other ways to categorize types in .NET. One of them is by the way the objects created based on those types are mapped to the computer memory. This will give us Value types and Reference types.
Value types 
An instance of a value type directly contains its data (value). stored in stack.
The value types are themselves split in 3 categories:
  1. The built-in value types -
  • the integer types (Byte, SByte, Int16, Int32, Int64, UInt16, UInt32 and UInt64)
  • the floating point types (Single and Double)
  • the logical type (Boolean)
  • other (Char, Decimal, InPtr and UInPtr) 
2. User-defined value types
3. Enumerations

Value types cannot equal 
null.

int a=null; will throw an error !!
Reference Type
Contrary to value types, an instance of a reference type does not directly contain its data (value), but instead contains some kind of a reference to the memory location of that value.

For example a String local variable has memory allocated on the stack for a reference to the contained string, not the string itself. In that case the string itself will be allocated on the heap and garbage collected.
Unlike Value types, reference types can be assigned the value null.
The reference types are themselves split in four categories:
  • pointers
  • arrays
  • classes
  • interfaces

An array is essentially a group of objects, usually of the same type, that can be accessed via an index.

The two main problems of arrays are:

* They are fixed length
* They support only one internal organization

Classes

Classes are themselves split in three:

* user-defined classes
* boxed value types
* delegates

Boxing and Unboxing
All types derive diretly or indirectly from System.Object (including value types by the way of System.ValueType).

Boxing and unboxing enable value types to be treated as objects.
Boxing a value type, packages it, inside an instance of the Object reference type. This allows the value type to be stored on the garbage collected heap.

------------------------------------------------------------------------------------------
int i = 123;
object o = (object) i; // boxing
-----------------------------------------------------------------------------------------
Please also note that it is not necessary to explicitly cast an integer to an object (as shown in the example above) to cause the integer to be boxed. Invoking any of its methods would also cause it to be boxed on the heap (because only the boxed form of the object has a pointer to a virtual method table):

--------------------------------------------------------------------------------------------
int i=123;
String s=i.toString(); //This call will cause boxing
---------------------------------------------------------------------------------------------

There is also a third way in which a value type can be boxed. That happens when you pass a value type as a parameter to a function that expects an object. Let's say there is a function prototyped as:

void aFunction(object value)

Now let's say from some other part of your program you call this function like this:

int i=123;
aFunction(i); //i is automatically boxed

This call would automatically cast the integer to an object, thus resulting in boxing.
------------------------------------------------------------------------------------------
The object o can then be unboxed and assigned to integer variable i:
------------------------------------------------------------------------------------------
o = 123;
i = (int) o; // unboxing
------------------------------------------------------------------------------------------
Performance of boxing and unboxing

In relation to simple assignments, boxing and unboxing are computationally expensive processes.
When a value type is boxed, an entirely new object must be allocated and constructed. To a lesser degree, the cast required for unboxing is also expensive computationally.

Unboxing extracts the value type from the object

Interfaces
It is a form of polymorphism . to have a single type of reference to the "common part" of different types that have "something in common".
The class libraries rely heavily on interfaces and a clear understanding of the concept is essential.
An interesting problem with interfaces compared with inheritance is that you do not get a default implementation (virtual parent methods) so you have to recode everything. The techniques and tools do exist here but there is always some extra work to do. More on that with generics...
Another way of type is by Reflection category (Class, Value types, Interfaces, Generics, etc.).
Yet another way is to distinguish the types that are directly supported by the runtime (built-in types) from those defined either in the class libraries or custom.
Those categories can also be intersected with one another, that will give us such things as "Built-in value types" or "System interfaces".

Data structures
------------------
Stack

A stack in an ordered list where insertion and deletion take place at one end called top of the stack (stack pointer) .So the last inserted item will be removed first. Data accessing in the order of Last in First Out Order[LIFO].

Queue,dequeue,Priority Queue

With a queue, you insert items at one and and extract them from the
other end -You can think of it as a line in a grocery store. The first one in the line is the first one to be served.Just like a queue.

i.e. you can ONLY get things out in the order in which they were inserted.FIFO (First In First Out)

With a deque, you can insert and/or remove from either end, so you get a
combination of stack behavior (remove the most recently inserted item)
or queue behavior (as above).

A priority queue is different from either of these. With a priority
queue, you specify an ordering by which items will be sorted. You
insert items and you remove items, but when you remove items, you get
them in sorted order. This is handy for things like tasks that have to
be completed. When a task arises that will need to be done, you put it
into the priority queue. When you're ready to carry out a task, you
pull one from the priority queue, and you'll get the highest priority
task that's waiting.

Linked List

A linked list is a data structure that consists of a sequence of data records such that in each record there is a field that contains a reference (i.e., a link) to the next record in the sequence.

Each record of a linked list is often called an element or node.
The field of each node that contains address of the next node is usually called the next link or next pointer. The remaining fields may be called the data, information, value, or payload fields.
The principal benefit of a linked list over a conventional array is that the order of the linked items may be different from the order that the data items are stored in memory or on disk. For that reason, linked lists allow insertion and removal of nodes at any point in the list, with a constant number of operations.
Linear and circular lists

In the last node of a list, the link field often contains a null reference, a special value that is interpreted by programs as meaning "there is no such node". A less common convention is to make it point to the first node of the list; in that case the list is said to be circular or circularly linked; otherwise it is said to be open or linea
Singly-linked lists contain nodes which have a data field as well as a next field, which points to the next node in the linked list
In a doubly-linked list, each node contains, besides the next-node link, a second link field pointing to the previous node in the sequence. The two links may be called forward(s) and backwards.
Attributes

First of all attributes are not types. They are elements of information that are added to a program element (assemblies, classes, method, etc.) to qualify it outside of the normal code associated with that element.

System attributes (part of the framework) and Custom attributes (built by the developer).

eg:get,set

Collections
Collection is a group of objects.
We have two sections with collections examples:

Generics

Generic programming or the use of parameterized types is not an object oriented concept.
The actual type will be obtained when you substitute the parameter type with a specific type (For example when you declare a variable of that type).
// C#
List myIntList = new List()

'// VB.NET
Dim myIntList As New List(Of Integer)

Delegates

A delegate is a type that defines a reference to a single function that
must have the same signature as the delegate definition. A signature is
a description of the type of the function parameters and its return
type. Like a class you can create an object of that type. The object
created is a reference to a function that can be assigned (set the
reference to a specific function), be passed as parameter or executed
(the function that is referenced is actually executed). Unlike an
interface, a delegate defines only one function and a delegate instance
can be created directly (no need to have another class implementing the
interface).

WPF(Windows Presentation Foundation)

Windows Presentation Foundation (WPF) is the code-name of the presentation (user-interfaces) sub system in Windows programming model and is used to create user interfaces

What Operating Systems does WPF support?

Windows Vista, Windows XP, and Windows 2003 Server.

What is WPF?
It is a new technology for creating rich graphical applications.
Windows Presentation Foundation (WPF) application is responsible for , drawing shapes, paths, and controls in windows.. You can import images, video, and sound. You can create storyboards that animate the visual or audio elements of your design, and optionally trigger those storyboards when users interact with your application.

WPF is the engine that is responsible for creating, displaying, and manipulating user-interfaces, documents, images, movies, and media in Windows Vista.

Physically, WPF is a set of libraries that have all functionalty you need to build, run, execute, and manage Windows Vista applications.

How XAML(Extensible Application Mark up Language) is related to WPF?

XAML is a new descriptive programming language developed by Microsoft to write user interfaces for next generation managed applications. XAML is used in WPF to represent the controls and code with the help of C#, Visual Basic, and other .NET Framework languages.

XAML can be think as ASP.NET and/or Windows Forms in Windows Vista. For example, to write a Web application in .NET 1.0, 1.1, or 2.0, you use ASP.NET and to write Windows Applications, you use Windows Forms. Now in Windows Vista and .NET 3.0, you will use XAML instead of Windows Forms and ASP.NET.

Does that mean XAML will replace ASP.NET and Windows Forms? YES and NO. Both ASP.NET and Windows Forms will also be supported on .NET 3.0 but you don't have to use them if you don't want.

How do I build WPF Applicaitons?
To build WPF application, you must install .NET 3.0 SDK. It can be found on MSDN downloads sites.
What do I need to run WPF Applications?
To run WPF applications, you must install .NET 3.0 SDK redistributable. It can be found on MSDN downloads sites.(http://www.microsoft.com/downloads/thankyou.aspx?familyId=f26b1aa4-741a-433a-9be5-fa919850bdbf&displayLang=en)
Get Started with WPF
Download a free version of Visual Studio 2008, if you do not have Visual Studio 2008 or express version here: www.c-sharpcorner.com/Downloads
After that, start learning about WPF in WPF section of C# Corner here:
There are some more WPF articles on www.longhorncorner.com
http://msdn.microsoft.com/en-us/beginner/bb308823.aspx
http://www.c-sharpcorner.com/uploadfile/freebookarticles/apress/2009jan07021710am/WPFIntro/1.aspx

http://msdn.microsoft.com/en-us/library/bb655895.aspx