Saturday, October 23, 2010
Tuesday, July 28, 2009
Constants vs Static Variables
Today I discussed with my colleague natwar on difference between use of constant variables and static variables.
Sometimes, we declare a class to store constant string and this functionality can also be implemented by using the static keyword.
I have created a small program to demonstrate the same.
Code Listing
namespace TestingApp
{
class Program
{
static void
{
Console.WriteLine( ClassWithConsts.HelloWorld );
Console.WriteLine( ClassWithStatic.HelloWorld );
}
}
class ClassWithConsts
{
public const string HelloWorld = "Hello World";
}
class ClassWithStatic
{
public static string HelloWorld = "Hello World";
}
}
After disassembling, we have come to know that, when we use constant variables, Compiler replaces them with their value in the source code.
This is not the case with the static variables, as every time they are used a new instance of the variable type is created and subsequently used.
Check the disassembled code

Now we will use constant variables instead of static for strings which do not change during the executon of the program. Thanks to ILDASM !
Monday, December 24, 2007
Google PicasaWeb API Example
Google has launched Picasa Web Albums Data API in march 2007 . Last week , I developed some code using this new API which is part GData API family. In case you are still wondering what GData APIs consists of then check out the official homepage.
Here are some of the things you can do with the Picasa Web Albums Data API:
- Include your public photos in your own web page, and allow users to comment on them (and have the comments stored in Picasa Web Albums).
- Write a plugin to manage your albums and photos from a desktop or mobile phone client.
- Create a custom screensaver to display your Picasa Web Albums photos on your computer.
Google is providing client libraries to help you write GData client applications in a variety of languages like java, python, c#, php, javascript.
Download the GData .NET Client Library
Now, create a new Console Application project for c#. Add a reference to GData.Client, Gdata.Extenstion and GData.Photos Dlls from the output directory of the first project.
Now the stage is ready.
Here is the code for a function which takes User name and name of the album as arguments and download all the pictures from this album.
private static void DownAlbum(string UserN, string AlbumN)
{
string fileName;
Uri uriPath;
WebClient HttpClient = new WebClient();
// Three important elements of PicasaWeb API are
// PhotoQuery, PicasaService and PicasaFeed
PhotoQuery query = new PhotoQuery();
query.Uri = new Uri(PhotoQuery.CreatePicasaUri(UserN, AlbumN));
PicasaService service = new PicasaService("Sams PicasaWeb Explorer");
PicasaFeed feed = (PicasaFeed)service.Query(query);
Directory.SetCurrentDirectory("c:\\");
foreach (AtomEntry aentry in feed.Entries)
{
uriPath = new Uri(aentry.Content.Src.ToString());
fileName = uriPic.LocalPath.Substring(uriPath.LocalPath.LastIndexOf('/')+1);
try {
Console.WriteLine("Downloading: " + fileName);
HttpClient.DownloadFile(aentry.Content.Src.ToString(), fileName);
Console.WriteLine("Download Complete");
}
catch (WebException we)
{ Console.WriteLine(we.Message); }
}
Code is easy to understand. I am using HttpClient.DownloadFile() to download file from picasaweb server. To improve readability I have not included error handling code here.
Monday, September 3, 2007
A project on OMR in C#
After googling and burning mid night oil for 3 days, I have found that the following things are required
1) OMR sheets -- OMR forms are typically multiple choice sheets, which may or may not be made of special paper and ink.
2) Scanner -- Since I want to develop a software based system, it should support a wide variety of scanners.
3) Recognization engine -- Image processing and analysis has to be done here, and data collected should be forwarded for further processing.
4) OMR Sheets management system
PS: More points may be added later.
Now, I have decided to build the Recognization Engine first and my colleagues will help in developing the rest of the system.
I have developed some graphics intensive apps. Softwares with impressive uncoventional UI ( latest one using WPF and Expression Blend posted here) and also small 2-D games . It was never required before to play directly with the pixels of a image.
Friday, July 27, 2007
VS 2008 'orcas' beta 2 released
MSDN Library for Visual Studio 2008 Beta 2 can be downloaded from this link .
I will spend next few days to grasp the changes in this new release. And come up with new posts soon.
Thursday, July 26, 2007
VS 2008 'orcas' beta 2 will be available in few days
Microsoft will announce Thursday morning the release of Visual Studio 2008 Beta 2. According to Scott Guthrie, the general manager of Microsoft's Developer Division, the release will be nearly feature complete and will likely be the last major release before the product is released to manufacturing in preparation for its launch on February 27, 2008.
Monday, July 9, 2007
Reading a XML file using JScript
My current project required me to consume and display data from a xml file. XML! hey microsoft has made programmer's life easy by providing various xml classes. But i was asked to use same old scripting languages. I started with javascript and then XMLDOM. Document Object Model, yeah we all have heard about it since last decade. Now let me show how you can also make use of XMLDOM using JScript
Requirements :
1. MSXML 3.0 or above
2. Text editor like notepad
3. Internet Explorer 4.0 or later
4. A XML file, Products.xml is included in the attached file
Note: If u have windows xp or 2003 installed on
var dom = new ActiveXObject("msxml2.DOMDocument.3.0");
First create a instance of msxml DOM object.Above code will work for MSXML 3.0 or above as "Msxml2.DOMDocument.3.0" is ProgID for MSXML 3.0.
For those who are still wondering, MSXML is the Microsoft XML Core Services.
dom.load("products.xml");
once this is done we can use various DOM methods and properties to access and manipulate the XML data.
var oNodes = dom.selectNodes("//Product[0]/*");
var node = oNodes.nextNode; alert(node.text);
This was my first experience with JScript and also MSXML. Also attached a hello world test file to get you started with MSXML DOM. Do write to me about any queries.
