Geeks With Blogs

News kaleidoscope 1817, lit. "observer of beautiful forms," coined by its inventor, Sir David Brewster (1781-1868), from Gk. kalos "beautiful" + eidos "shape" (see -oid) + -scope, on model of telescope, etc. Figurative meaning "constantly changing pattern" is first attested 1819 in Lord Byron, whose publisher had sent him one.

Kaleidoscope Everything under the sun, ending in .Net

Problem Scenario:

There is an enum keeping track of operations to be performed on a table

Public Enum PartitionKey {
Createtask,
Updatetask,
Deletetask
}

User is entering the value for the operation to be performed and the code to check the value entered in switch case.

Switch (value)

         case PartitionKey.Createtask.ToString():
         {
         Create();
         break;
         }
         case PartitionKey.Updatetask.ToString():
         { 
         Update(); 
         break;
         }
         case PartitionKey.Deletetask.ToString():
         { 
         Delete();
         break;
         }
}
and it displays as error as “.”

Solution: One of the possible implmentation is as below.

Public Enum PartitionKey: byte {
Createtask,
Updatetask,
Deletetask
}
Switch ((PartitionKey)(Int32.Parse(value)))
{
         case PartitionKey.Createtask:
         {
                  Create();
                  break;
         }
         case PartitionKey.Updatetask:
         { 
                  Update();
                  break;
         }
         case PartitionKey.Deletetask:
         { 
                  Delete();
                  break;
         }
         default:
         {
                  break;
         }
}

Posted on Monday, December 13, 2010 12:51 AM | Back to top


Comments on this post: Using Enums for comparing string values in Switch

# re: Using Enums for comparing string values in Switch
Requesting Gravatar...
Kindly moderate the comments on the thread. :)
You can delete the spam comments from the admin section!
Left by Sarang on Dec 29, 2010 11:20 PM

Your comment:
 (will show your gravatar)


Copyright © kaleidoscope | Powered by: GeeksWithBlogs.net