Showing posts with label .NET Concepts. Show all posts
Showing posts with label .NET Concepts. Show all posts

Tuesday, August 28, 2007

How Generic Collections work inside?

public class TypeSafeList<T>
{
T[] innerArray = new T[0];
int currentSize = 0;
int capacity = 0;

public void Add(T item)
{
// see if array needs to be resized
if (currentSize == capacity)
{
// resize array
capacity = capacity == 0 ? 4 : capacity * 2; // double capacity
T[] copy = new T[capacity]; // create newly sized array
Array.Copy(innerArray, copy, currentSize); // copy over the array
innerArray = copy; // assign innerArray to the new, larger array
}

innerArray[currentSize] = item;
currentSize++;
}

public T this[int index]
{
get
{
if (index < 0 index >= currentSize)
throw new IndexOutOfRangeException();
return innerArray[index];
}
set
{
if (index < 0 index >= currentSize)
throw new IndexOutOfRangeException();
innerArray[index] = value;
}
}

public override string ToString()
{
string output = string.Empty;
for (int i = 0; i < currentSize - 1; i++)
output += innerArray[i] + ", ";

return output + innerArray[currentSize - 1];
}
}

Monday, August 27, 2007

. NET Type Safety

Type safe means preventing programs from accessing memory outside the bounds of an object's public properties A programming language is type safe when the language defines the behavior for when the programmer treats a value as a type to which it does not belong. Type safety requires that well-typed programs have no unspecified behavior (i.e., their semantics are complete). Languages such as C and C++, which allow programmers to access arbitrary memory locations, are not type safe. An unsafe programming language supports operations (such as accessing arbitrary memory locations), which are not defined in terms of the language semantics. Type safety is a property of the programming language, and not of the programs themselves.

. NET Type Safety

Sunday, August 26, 2007

Microsoft .NET Remoting - Complete Walkthrough

 

Remoting enables you to write applications that allow objects in different .NET application domains to communicate with each other. In general, objects living in different application domains cannot access each other directly. They need an infrastructure that makes communication possible. That's what .NET Remoting is for. It's the .NET analogy to DCOM, for those of you who are familiar with DCOM. It allows interprocess and intermachine communication between objects.

Look here for a great power-point presentation and also attached interview transcript of the author about Microsoft .NET Remoting - Complete Walkthrough...Just follow him!!! !!!

Microsoft .NET Remoting WebCast

String vs. StringBuilder - How they Work?

 

String objects in .net are immutable. Once the string has been created, the value can't be changed. When you type s = s + "foo";, you actually discard the old s and create a new string object containing the result of the concatenation. When repeated several times, you end up constructing many temporary string objects.

StringBuilder, on the other hand, represents a mutable string. The class itself contains quite a few methods to change the contents of the string. This includes appending new strings to the end - the most common operation by far. Internally, StringBuilder reserves a buffer of memory which is used only partially at first (usually). Concatenations that fit into the buffer are just pasted in and the string length is changed. If the new resulting string wouldn't fit into the buffer, a new buffer is allocated and the old contents are moved in. In no case new objects need to be created.

The sore points of StringBuilder are the construction cost (which makes the "magic number" practically always at least 3) and the cost of allocating a new buffer when the resultant string would exceed the current buffer size. The latter one explains why the preknowledge (or a good estimation) of the resultant string size helps so much: StringBuilder can just allocate a sufficient buffer once.

.net String vs. StringBuilder - concatenation performance

Great articles on Data Structures and Collections in .NET

Hi,

I would recommend reading these below mentioned articles from MSDN for any programmer who wants to develop or is developing using Microsoft .NET Framework technologies.

Part 1: An Introduction to Data Structures
Part 2: The Queue, Stack, and Hashtable
Part 3: Binary Trees and BSTs
Part 4: Building a Better Binary Search Tree
Part 5: From Trees to Graphs
Part 6: Efficiently Representing Sets

Data Structures in .NET

 

Why data structures are important, and their effect on the performance of an algorithm. To determine a data structure's effect on performance, we'll need to examine how the various operations performed by a data structure can be rigorously analyzed. Finally, we'll turn our attention to two similar data structures present in the .NET Framework: the Array and the List. Chances are you've used these data structures in past projects. In this article, we'll examine what operations they provide and the efficiency of these operations.

The Queue and Stack. Like the List, both the Queue and Stack store a collection of data and are data structures available in the .NET Framework Base Class Library. Unlike a List, from which you can retrieve its elements in any order, Queues and Stacks only allow data to be accessed in a predetermined order. We'll examine some applications of Queues and Stacks, and see how these classes are implemented in the .NET Framework. After examining Queues and Stacks, we'll look at hashtables, which allow for direct access like an ArrayList, but store data indexed by a string key.

While arrays and Lists are ideal for directly accessing and storing contents, when working with large amounts of data, these data structures are often sub-optimal candidates when the data needs to be searched. The binary search tree data structure, which is designed to improve the time needed to search a collection of items. Despite the improvement in search time with the binary tree, there are some shortcomings. SkipLists, which are a mix between binary trees and linked lists, and address some of the issues inherent in binary trees.

A graph is a collection of nodes, with a set of edges connecting the various nodes. For example, a map can be visualized as a graph, with cities as nodes and the highways between them as edged between the nodes. Many real-world problems can be abstractly defined in terms of graphs, thereby making graphs an often-used data structure.

Finally, in Part 6 we'll look at data structures to represent sets and disjoint sets. A set is an unordered collection of items. Disjoint sets are a collection of sets that have no elements in common with one another. Both sets and disjoint sets have many uses in everyday programs, which we'll examine in detail in this final part.

Part 1: An Introduction to Data Structures

Monday, July 30, 2007

Consequences of Strong Naming Assembly in .NET

Any code you have that uses this assembly, will need to be recompiled with a reference to the new assembly with the newer version.

Strong named assemblies can only reference other strong named assemblies.

If your product includes many assemblies (.NET DLL's) and you want to ship only one of them as a hotfix, you will not be able to because your other assemblies will still refer to old version of the DLL. So either restrict to the same old version or use the .Net Framework configuration tool to forward the old version to the new version.

If you have classes that need to be serialized, the engine includes type information in the serialized data, that way it can be reconstituted later. If you the AssemblyFormat property is not set correctly, you could end up with a situation here you have stored some data, upgraded your application (maybe because of a bug fix), and then
error when you try to load your serialized database (even though nothing in that particular class has changed).

Unless your assemblies need to be placed in the GAC, or run as COM+ component, or some other special case,
strong-naming them probably is not necessary.

Monday, July 2, 2007

Enum Types in .NET or C# .NET

Enum types implicitly inherit the System.Enum type in the Base Class Library (BCL). This also means that you can use the members of System.Enum to operate on enum types.

I have included few code snippets which are self-explanatory for use of enums.

public
enum Volume : byte
{
Low = 1,
Medium,
High
}


void ShowVolume(int v)

{

Volume vol = (Volume)v;

If(vol == Volume.Low)


}


// get a list of member names from Volume enum,
// figure out the numeric value, and display
foreach (string volume in Enum.GetNames(typeof(Volume)))
{
Console.WriteLine("Volume Member: {0}\n Value: {1}",
volume, (byte)Enum.Parse(typeof(Volume), volume));
}


// get all values (numeric values) from the Volume
// enum type, figure out member name, and display
foreach (byte val in Enum.GetValues(typeof(Volume)))
{
Console.WriteLine("Volume Value: {0}\n Member: {1}",
val, Enum.GetName(typeof(Volume), val));
}


Given the type of the enum, the GetValues method of System.Enum will return an array of the given enum's base.

Sunday, May 13, 2007

What do you mean Asynchronous Database Commands ?

When we execute any database. Thread that executing command waits before command get fully executing before executing any additional code. Thread is blocked for another process. But Asynchronous Database Commands solve this problem when database command is executing current thread can continue on other process.Thread can execute a no of database command. There are two benefits of using Asynchronous Database Commands.
A.Executing Multiple Databse Commands simultaneously improve performance.
B. Because ASP dot Net framework uses a limited pool service for request. Whenany request for a page is comes its assign a thread to handle the request. If framework is out of thread then job is in gueses we get error 503. But if we are using asynchronous database command then current thread is release back to current thread pool."

Friday, May 11, 2007

What is service oriented architecture - SOA ?

In this changing business climate, where globalization and demanding customers require agility and flexibility, retailers' IT systems are not helping them in meeting these expectations. Most of the legacy retail systems were built following tightly coupled point-to-point integration principles. Service orientation offers great benefits in moving from these legacy systems to more flexible and agile systems.

· SOA is a design philosophy independent of any product, technology, or industry trend.

· SOAs can be realized using Web services, but using Web services will not necessarily result in a SOA

· EDI, CORBA, and DCOM were conceptual examples of SO.

· SOA is not a methodology.

· SOAs are like snowflakes: No two are the same.

· SOA should be incremental and built on your current investments.

· SOA requires tools, not consultants.

· SOA is a means, not an end.

 
Dotster Domain Registration Special Offer