Wednesday, February 22, 2012

readonly v/s const in C#

readonly

Facts

1) It’s a modifier which is assigned while field declarations.
2) Also called run time constant.
3) Value can be assigned in 2 ways:
a. During declaration
//Initializing value during declaration
readonly int Readonly = 5;
b. By constructor
class ReadOnlyDemoClass
{
 //Declaration
 readonly int Readonly;

 //Initializing value by constructor
 ReadOnlyDemoClass(int x)
 {
  Readonly = x;
 }
}
4) IL

readonly Properties

1) Only get; method should be declared and defined in readonly properties
2) Value can be assigned in 2 ways:
a. During declaration
//Variable Declaration and initialization
private int readonlyvar = 5;
//Readonly Property Declaration - No set method
internal int ReadonlyProperty { get { return readonlyvar; }}
b. By constructor
//ReadOnlyDemo Class
class ReadOnlyPropertyDemoClass
{
 //Variable Declaration and initialization
 private int readonlyvar = 5;
 //Readonly Property Declaration - No set method
 internal int ReadonlyProperty { get { return readonlyvar; }}
 //Constructor
 public ReadOnlyPropertyDemoClass(int propVal)
 {
  //Initializing value by constructor
  readonlyvar = propVal;
 }
}

//Program Class
class Program
{
 //Main Method
 static void Main(string[] args)
 {
  ReadOnlyPropertyDemoClass rpdc = new ReadOnlyPropertyDemoClass(5);
  Console.WriteLine(rpdc.ReadonlyProperty);
 }
}
3) IL
       
4) Static readonly properties can be assigned only during declaration or by static constructor
5) Static readonly properties should be associated only with static variables.

Errors

1) Initializing the readonly variable by any different method.
class ReadOnlyDemoClass
{
 readonly int Readonly;
 static void Main(string[] args)
 {
  ReadOnlyDemoClass rd = new ReadOnlyDemoClass();

  //Initializing the variable from somewhere else
  rd.Readonly = 5; // Compilation Error: A readonly field cannot be assigned to (except in a constructor or a variable initializer)
 }
}
Resolution: Use the above two mentioned ways to initialize the readonly variable.

2) Assigning Static readonly variable by normal constructor
   //ReadOnlyDemo Class
   class ReadOnlyDemoClass
   {
    //Static readonly field
    static readonly int Readonly;

    //Constructor
    ReadOnlyDemoClass(int x)
    {
     //Initializing value by constructor
     Readonly = x; // Compilation Error: A static readonly field cannot be assigned to (except in a static constructor or a variable initializer)
    }

    //Main Method
    static void Main(string[] args)
    {
     ReadOnlyDemoClass rd = new ReadOnlyDemoClass(4);
    }
   }
Resolution: Initialize the static readonly variable whilst declaration or using static constructor

Additional References

- Msdn Using Properties (C# Programming Guide)
http://msdn.microsoft.com/en-us/library/w86s7x04(v=vs.100).aspx

const

Facts

1) It’s a modifier which is assigned while field declarations.
2) Also called compile time constant.
3) Value can be assigned only during declaration:
a. During declaration
//Initializing value during declaration
const int constantvar = 5;
4) IL
   

5) As you can see in IL that const by itself is a static literal therefore, static modifier is not allowed for constants.
6) A constant can be used in an expression:
//Circle Class
class Circle
{
 //Variable Declaration and initialization
 const double pie = 22/7;
 //Area Method
 double Area(double radius)
 {
  //Use of constant in an expression
  return 2 * pie * radius;
 }
}
7) Expression containing constants:
   int ConstAssignedVariable = Constant; // Valid Expression
   const int ConstAssignedConstant = Constant; // Valid Expression
   const int CalculatedwithConstConstant = Constant + 3; //Valid Expression
   const int VarAssignedConstant = Variable; // Compilation Error: The expression being assigned to 'VarAssignedConstant' must be constant
   const int CalculatedwithVariableConstant = Variable + Constant; // Compilation Error: The expression being assigned to 'CalculatedwithVariableConstant' must be constant

Errors

1) Variable assignment:
       //Variable Declaration and initialization
const string constantvar = DateTime.Now.ToShortDateString();// Compilation Error: The expression being assigned to 'constantvar' must be constant
Resolution: Either assign the values which can be calculated at runtime or some constants.

2) Static Constants
   static const int Constant = 2; // Compilation Error: The constant 'Constant' cannot be marked static
    Resolution: Constants are implicitly static therefore, no need to mark them as static


Additional References



Difference between readonly and const


Thursday, July 9, 2009

Google Chrome Operating System

After the success of Chrome(30 million users recorded), Google has decided to launch an OS that can be said as a natural extension of Google Chrome.

Google is initially targeting at the notebooks by developing an open source, lightweight OS and it will be available for consumers in the second half of 2010.
The key aspects on which they are concentrating are Speed, simplicity and security. It is an entirely new concept different from Android.

They believe that the operating systems that browsers run on were designed in an era when there was no web, so a new concept is required. Stay tuned for updates in the near future.

Glimpses











Saturday, April 25, 2009

Google Gadgets

What are gadgets powered by Google?
Gadgets powered by Google are miniature objects made by Google users like you that offer cool and dynamic content that can be placed on any page on the web.

Gadgets might come in handy when you're at work (to-do list, currency converter, calendar), at school (calculator, Wikipedia, translation tool),or just passing time (news, blogs, games). You can add gadgets you like to iGoogle and, if you have Google Desktop installed, you can also add gadgets to your computer's desktop.

Few Gadgets















You can find Google Gadgets on : http://www.google.com/ig/directory?synd=open

Microsoft Surface

Microsoft Surface (Codename: Milan), is a multi-touch product from Microsoft which is developed as a software and hardware combination technology that allows a user, or multiple users, to manipulate digital content by the use of natural motions, hand gestures, or physical objects. It was announced on May 29, 2007 at D5 conference. Initial customers will be in the hospitality businesses, such as restaurants, hotels, retail, public entertainment venues and the military for tactical overviews. The preliminary launch was on April17, 2008, when Surface became available for customer use in AT&T stores. The Surface was used by MSNBC during its coverage of the 2008 US presidential election; and is also used by Disneyland's future home exhibits, as well as various hotels and casinos. The Surface is also featured in the CBS series CSI: Miami. As of March 2009, Microsoft had 120 partners in 11 countries that are developing applications for Surface's interface.

URL for cool Videos: http://www.microsoft.com/surface/

Friday, April 17, 2009

Microsoft Office 14

Office 14("Office 14" for short) is the working title for the next version of theMicrosoft Office productivity suite for Microsoft Windows. It is officiallyannounced that Office 14 will ship in 2010.

Office 14 will implement the ISO compliant version of Office Open XML whichwas standardized as ISO 29500 in March 2008. Microsoft plans to offer aWeb-based version of its Office productivity suite, known as Office Web,that will debut with the release of Office 14. Office Web will includeonline versions of Word, Excel, PowerPoint and OneNote.

The next versions of Microsoft Office Visio, OneNote, Microsoft OfficeProject, and Publisher will feature the ribbon interface element used inother Office 2007 applications.

Office 14 may be the first version of Office to ship in both 32 Bit and64-bit Versions for Windows Vista and Windows 7, while still supportingWindows XP.


Monday, February 9, 2009

Intel Parallel Studio



Intel Parallel Studio is a set of software development tools developed by Intel that plug into Microsoft Visual Studio to assist in developing programs for parallel computing. Parallel programming enables software programs to take advantage of multi-core processors from Intel and other processor vendors.



Tools inside Studio:

* Intel Parallel Advisor: The Discovery tool

* Intel Parallel Composer: Develop effective applications with a C/C++ compiler and advanced threaded libraries.

* Intel Parallel Inspector: Ensure application reliability with proactive parallel memory and thread error checking.

* Intel Parallel Amplifier: Quickly find bottlenecks and scale formulticore with this easy-to-use performance analyzer and tuner.

Intel announced Parallel Studio during their Intel Developer Forum in August 2008 along with a web site to sign up for their open beta program withproduct to follow in late 2009. Intel and Microsoft are working together tomake Intel and Microsoft product compatible by adopting a common runtime called the Microsoft Concurrency Runtime, part of Visual Studio 2010.

Website to download Beta Version: http://www.intel.com/cd/software/products/asmo-na/eng/399359.htm

Reference: http://en.wikipedia.org/wiki/Intel_Parallel_Studio



IIS 7.5


IIS (Internet Information Services) is a secure, reliable, and scalable Webserver that provides an easy to manage platform for developing and hosting Web applications and services. 'IIS 7.5' is the latest update to the IIS 7.0 server. This release comes with Windows Server 2008 R2 and Windows 7. This integrates many separate downloads available from Microsoft into the release.
Hierarchy of Managed Entities






















Features/ Components:

- IIS Windows Process Activation Service (WAS)
- IIS Application Pool
- IIS Worker Process
- IIS Protocol Adapter
- IIS FTP Service
- IIS Web Management Service (WMSvc)
- IIS Application Host Helper Service (AppHostSvc)
- IISADMIN Service
- IIS Hosted Web Core
- IIS World Wide Web Publishing Service (W3SVC)
- IIS Web Site
- Active Server Pages (ASP)