Sunday, July 25, 2010

Sealed Class


Sealed Class is the class which can not be inherited.the members/methods in the sealed class can not be derived from any other class. A compile-time error occurs if a sealed class is specified as the base class of another class. By default, structs are sealed; not classes in .NET

Here we see evidence of the small but measurable speedup allowed by the use of the keyword sealed in the C# programming language. The benchmark shows that for the very simplest interface methods, the sealed keyword can improve performance by about a third of a nanosecond per method invocation. For interface-heavy programs, the sealed keyword decoration can result in a speedup on all method calls with no downside.

~~~ Sealed class benchmark results (C#) ~~~       
See "Benchmark" section for the code compared.

TestA.GetNumber (regular): 2.490 ns
TestB.GetNumber (sealed): 2.162 ns [faster]

So, the keyword sealed provides a way to demand that the class not to be inherited from, but it is also useful for performance optimization.

Sunday, July 18, 2010

readonly preferance


C# has two versions of constants. They are compile timed 'const' and run timed 'readonly'. As named, const variables are replaced with the value of that constant in the object code. But readonly constants are evaluated at runtime; they are referenced with IL( Intermediate Language) generated variables not the value. Compile time constants can be used only for primitive types.

readonly for instance constants are used to store different values for each instance of a class type. Compile time const are static constants by definition
// compile time
public const int Millennium = 2000;

// run time
public static readonly int thisYear = 2010;

Advantage of using const over readonly is performance, where as readonly prefers the increased flexibility due to runtime compatability constants.

Thursday, July 8, 2010

MSDTC-Transaction Controller


On writing an .NET application with multiple LINQ insert/update statements TransactionScope is useful.
Letz say we are inserting EmployeeInfo table, then EmployeeSalaray table, followed by EmployeeAttendance table.
When the application completes all work it wants to perform in a transaction, Complete method informs transaction manager that it is acceptable to commit the transaction. Failing to call this method aborts the transaction. Isn't it cool?

But, I got an error '[System.Transactions.TransactionManagerCommunicationException] during TransactionScope execution. On analysis, it has been found Network access for Distributed Transaction Manager (MSDTC) has been disabled by default in XP. MSDTC is a transaction manager which permits client applications to include several different sources of data in one transaction, and which then coordinates committing the distributed transaction across all the servers that are enlisted in the transaction.

To resolve this issue, MSDTC is enabled via 'Control Panel->Administrative Tools->ComponentServices->MyComputer' MSDTC properties. You need to click on Security Configuration button under Transaction Configuration panel. In that section, enable 'Network DTC Access' After this setup, my application runs smoothly and TransactionScope is successful.

Tuesday, June 29, 2010

Technology Populism


Technology Populism — information workers provisioning technology outside of IT's auspices — is a topic of great interest to both technology vendors and IT departments. But is it more hype than reality? No. Information
workers are increasingly playing a role in selecting and managing the smartphones, computers, and software they use to get their jobs done. And because IT departments feel the necessity of meeting the growing needs of a distributed workforce while cutting costs, we see them increasingly allowing some technology autonomy for workers. For technology product marketers, this means speaking directly to end users about solving their specific business problems. Going forward, technology vendors will have to design, develop, and market products directly to a variety of information workers who, like consumers, have myriad choices

Technology populism is driven by people's need to interact. For many employees, the telephone and e-mail are being replaced by text messaging, instant messaging and mobile devices such as iPhones and Blackberrys, and social computing tools such as Facebook and Wikipedia. Drivers behind technology populism include: (1) Cheap broadband at home and work as personal and professional lives converge (2) A new generation of applications based on network interactions

To compete among the niche group, IT managers to be driven by ‘technology populism'

Friday, June 18, 2010

No(n parameter) constructor in Value Type


There are two key types in .NET framework (1) Value (2) Reference. As we know, value consumes stack and reference uses heap memory to store direct and indirect data. On working in Value type .NET objects, got the quite
interesting observation.

In terms of constructor, there are two significant differences between value and reference types.
1. Value type can't define non-parameter constructor where as reference will.
2. If no constructor is defined, .NET Compiler can produce default non-parameter constructor for reference type, where as value type can't.

1. Non parameter
On writing the below code with parameterless constructor, .NET compiler throws the error 'Structs cannot contain explicit parameterless constructors'
public struct RectangleInfo {
public RectangleInfo() {

2. No constructor
On using ILDASM to inspect the members of the value type, a parameterless constructor is not a member of the structure as marked in the attached image. But during the app execution, .NET framework has ability to instantiate a value type by using a language's constructor called implicit default constructor.

Sunday, June 13, 2010

Recommendation Note


This week is in vacation mode at Goa beach resort;completely out of work station. Got a surprise recommendation note from Dave, one of the popular web master.

Last year, published an article in code project (http://www.codeproject.com/KB/silverlight/DB_in_SL3.aspx). CRUD explains the complete operation in any language; itz about Silverlight 3. Dave recommended it(http://www.daveenjoys.com/2010/05/20/introduction-to-web-net-programming/) with code example category. In general, motivation drives additional energy and so i'm ready to publish next CRUD article in ASP.NET MVC Framework.

Truth, naked, unblushing truth, the first virtue of all serious history, must be the sole recommendation of this personal narrative.”-Edward Gibbon(1780). Thanx Dave!

Saturday, June 5, 2010

HTML5 beats


HTML5 beats Adobe Flex, Microsoft Silverlight and Oracle JavaFX. Here u go!
http://bexhuff.com/2009/06/html-5-versus-flash-flex

Thought works to back up:
  • Plug in Hell: Except HTML 5, plug in is required to install in the customer machine for Adobe Flex, Microsoft Silverlight, and Oracle JavaFX by design. In the current IT, there are lot of focus towards app security. But, plug-in design leaks the power of security and provides the high probability of hacking/security break operation.
  • Next Gen Web: As MS web developer, Silverlight is not the only option to build the next gen web applications. Better choice would be ASP.NET MVC, WCF and Entity framework for UI, Service and DB app layers. Still, HTML5 UI capability exceeds other technologies.
  • Browser support: Though HTML5 spec is evolving, all browsers will support HTML 5 completely by 2010 end. Major browsers like Firefox 3, Internet Explorer 8, Chrome 2 and Safari 4 are already supporting.
  • Performance: In terms of performance, built-in browser support execution faster than the custom plug in app.

Google wave is built on HTML5 and more list to go! CTOs may have more tech justifications to switch.