My Recent Speaking Presentations

Presenting at Florida Gulf Coast University (Careers in Technology)

Tonight, Charlene Gamero and I did a presentation on Careers in Technology to students at FGCU. There was a solid turn out, mostly because they were forced for an assignment, but we’ll take credit anyway.

I mentioned during the session that writing a blog was an extremely beneficial endeavor and in doing so remembered how I’ve neglected to write anything within the past month. Oops.

So, to both fill a little content, and provide the material for any of the students that were interested please enjoy this short post of the slide deck from our presentation.

Careers in Technology Presentation

Presenting at Oracle Open World (Value of Upgrading to Release 12.1 of Oracle Manufacturing)

Oracle OpenWorld 2011

On Oct. 6th, I presented on a customer panel regarding our new implementation of Oracle EBS, Agile PLM, and Oracle MOC. Though the title of the talk was a little misleading for my particular part (being a fresh implementation, not an upgrade), there was a lot of good information covered that is only found in R12; specifically, the reasons for our project – Manufacturing Execution System (MES) and Manufacturing Operation Center (MOC). There were two other customer speakers which did a great job to round out the session. I’ve included the slide deck (with the other presenters information excluded since I did not request their permission for publishing) in the link below.

On a sidenote, Open World was a lot of fun and educational though quite sad just prior to the concert when many of us found out Steve Jobs had passed away.

Value of Upgrading to Release 12.1 of Oracle Manufacturing Presentation

Moving to the Cloud, as a Consumer

Recently, I’ve been thinking a lot about the cloud. As a .NET developer, most of my thoughts have been on whether there were any projects I had which would make sense to reside on Azure. I struggled with the temptation of putting something up for the pure sake of trying it out but couldn’t really come up with a valid business case for the current suite of applications my team develops on. The assumption is there that moving applications to the cloud have some immediate benefit, such as scalability, ease of use in future deployments, and minimizing the need for internal infrastructure maintenance. However, whether these benefits would materialize is still in question and in most cases there simply isn’t a need right now.

So, with all of the uncertainty of putting business critical systems in the cloud yet, I thought I would try as a consumer first. I broke down my current day to day needs from my machine to see what I could potentially offload to the cloud. Here is my initial list:

  • Programming
  • Office
  • Pictures
  • Videos
  • Virtual Images
  • Note Taking
  • Email
  • Instant Messaging (Communication)
  • Twitter/Blogging/Social
  • System Administration (putty, VNC, remote desktop)
  • Zune/Music/Podcasts (WP7 Downloads)

Programming

This is a difficult one because this is where I draw on the horsepower of my machine throughout the day. I did work with a consultant about eight months back where he was running his development environment purely inside an Amazon EC2 instance that he would remote into whenever needed. There are some pretty nice advantages to this, such as, being able to access your full development environment from a netbook or lightweight, inexpensive laptop. Also, this removes the worry about breaking, losing, or having your primary development machine stolen.

The two options I am currently looking into are the VM role in Azure or Amazon EC2.

In addition to the development environment and OS, I focused on source control. Most companies that employ full time developers have centralized source control. However, if you’re on your own, or want to have separate source control for your non-work related projects, there are several options you can explore.

Several companies host Team Foundation Server (TFS) for a monthly fee of anywhere from $15-40 per user per month. Check out a list of TFS hosting companies from Microsoft.

If you are working on purely open source projects that you would like to source control, you can also host your code on Codeplex.

For more cost effective cloud-based source control (as low as $7 per month), try comparing some of the Subversion providers.

Office

There are quite a few options for storing documents online, but besides Office 365, I haven’t seen a really complete set of tools for developing document content without a local install.

A free alternative to Office 365 is Google Docs for basic document types.

Pictures/Videos

I am still on the lookout as to how I want to store pictures and videos. My current search has narrowed me down to Photobucket and Flickr with Flickr being the clear favorite for me. However, if someone has a really great suggestion, please let me know because I’m not quite sold yet. With either solution, it looks like you’re probably going to have to pay a fairly nominal amount in order to make this a truly usable option.

Virtual Images

See Amazon EC2 and Microsoft Azure VM Role above.

As a side comment, I really like spinning up VM’s for specific purposes instead of polluting my machine with hacks and patches to get all of the software I need to run on a single instance without causing headaches.

Note Taking

This is an interesting one. I had been diligently using OneNote for quite a while now and only last week switched to Evernote. I am pretty confident I will be staying with Evernote for one primary reason, compatibility. Above everything else, is the wide array of compatibility for devices and operating systems. I run an Ubuntu environment in addition to my Win7 and WinXP VM’s as well as I may be looking into the Asus eee Transformer 2 tablet when it comes out in October. Both Linux and Android Honeycomb do not support OneNote to my knowledge and do not require any additional license purchases for OneNote.

One thing I did like about OneNote a little better was the much richer text entry for note taking that OneNote offered, however for my personal notes it is something I can live with in Evernote.

One final note, for Evernote Pro Edition there is a charge of $5 per month which allows greater bandwidth usage per month for storing your notes.

Email

There are countless options for webmail, however I have separated my work email through company exchange and my personal email through Google Business Apps. I use the free business version so I can maintain my personal domain instead of gmail.com.

Instant Messaging

There are several options here, especially around which particular instant message client you used locally, however if you want to aggregate nearly all of the major services and access a completely web-based client, then meebo.com is a decent choice.

Twitter/Blogging/Social

All of the usual suspects for online tools. Twitter, Hootsuite, WordPress, Blogger, Facebook, LinkedIn, etc.

Obviously, I use WordPress for my blog but I included Blogger because many colleagues of my use Blogger and like it quite a bit.

System Administration

In most cases these days, this means the following tools I need to access: PuTTY, VNC, and Remote Desktop. PuTTY is nice since there is no install needed, so I can put it on my cloud file storage (read below) and access it directly. Sometimes I wish more programs were like this.

Zune/Music/Podcasts

Viable contenders include Amazon, Spotify, and Pandora. Unfortunately for my WP7, Zune needs to be locally installed and occasionally help sync my physical device. If anyone knows of a way around this or really good services for storing and accessing all of your music please let me know.

General Storage

Again, there are a lot of options for simple file storage. I’ve tried a few and here are the ones I liked best.

Microsoft’s Skydrive, used by several applications including OneNote gives you 5 GB of free space and the ability with Windows Live Mesh to automatically sync files across several machines. Photos I take with my WP7 automatically are uploaded to Skydrive for safe keeping (and helps limit the space taken up on my phone itself). The downside, is that I had several problems with Windows Live Mesh not working properly inside my guest VM’s and often failing to sync or connect to the service on my host machine. I still use Skydrive for my WP7 photo storage automatically, but I’ve switched off for file storage.

Google Docs was the original location of my offline stored documents but it’s fairly crude interface and lack of support for so many file types hindered my long term use.

Ubuntu One is very similar to Skydrive and performs live syncing as well, but to my understanding is only for the web and Ubuntu operating system. I also ran into problems connecting to the service often with Ubuntu One but it worked enough to make it on the list.

Finally, the service that I currently run and plan to use for a long time is Dropbox. Similar to Windows Skydrive, Dropbox is both a web version and a client installed helper application which monitors a local folder syncing files to and from the cloud. I can readily install the client tool in multiple operating systems, inside of both host and guest VM’s, and it seems to always connect in the background without problems.

There is a cost for Dropbox depending on the amount of storage you need and if it is quite large you may want to continue comparative shopping. You can view their price chart to help make your decision as to whether Dropbox is right for you.

Not Everything Can Go to the Cloud

Unfortunately, there is still quite a bit that I need to run natively, especially anything that requires communication to physical devices (Kinect, WP7, USB devices, video camera, etc.)

Also, certain development requirements may not be able to run in a virtualized environment such as the Windows Kinect SDK, XNA Game Studio (this may no longer be true but it was for quite a while and I’ll leave it up to someone else to fact check as it’s getting late).

Other Useful Web-based Services

Passpack for storing passwords online.
Delicious for storing bookmarks online.
Mint for personal spend tracking and planning.
Zillow for depressing home valuation and trending.
Bitly for url shortening and link tracking.

TFS Management with Team Foundation Sidekicks 2010

Recently, I’ve had a series of unfortunate events regarding my development environment. I’ve had some hard drive issues, some difficulties with a VM that I had been working on, and so it goes. All of these problems led to a rebuild recently and the spin up of a brand new development environment.

Unfortunately, rebuilding your trusty dev environment is never as quick and easy as you think it will be and I was left with a few files orphaned from TFS in the old Workspace. If you’re not familiar with this, Team Foundation Server (TFS), the “best-more-than-just-source-control” source control, is Microsoft’s top of the line source control and project/build management software for development environments. When working with TFS, you use Workspaces which map a local directory on your machine to a server source control directory. All check-ins/check-outs are controlled and attached to the activity in this Workspace. Because these Workspaces are machine specific, if you abruptly change computers, you will need to create a new Workspace, and though the same user account can be used to attach to TFS and create the Workspace, you can (if you’re not careful, like I was unfortunately) leave files checked out to yourself in a different Workspace. Since this Workspace is no longer active (computer may be replaced), the Workspace is left in limbo.

There are of course ways to clean this up natively with TFS; however they are command line only tools. Now all true geeks should be comfortable working in command line, but to be perfectly honest, this activity is so rarely executed that it is much, much, much easier to do with a graphic tool called Team Foundation Sidekicks 2010 instead of returning back to documentation or Bing (noticed how I didn’t say Google).

So, without any further ado, let’s run through the quick tutorial of installing and using Sidekicks.

Step 1: Know Where to Get It

Mosey on over to Attrice to download the appropriate version. For TFS 2010, you will want Team Foundation Sidekicks 2010, for prior versions of TFS; you will want Team Foundation Sidekicks.

I will be installing 2010 in the following screenshots.

TFS Sidekicks 2010 Download

Step 2: Install and Configure to Your TFS

Now that you’ve downloaded the application, go ahead and install. No instruction necessary here, just run the install package.

Once you are up and going, you will be asked to Connect to a Team Foundation Server. Enter your server information and a valid administrator privileged TFS user account and password.

TFS Sidekick 2010 Connect to TFS Configuration

Step 3: Using Sidekicks

Sidekicks has several areas of TFS you can administer. See the screenshot below to view the Workspace, Status, History, Label, Shelveset, Users View, and Code Review options. To clean up my orphaned Workspace guess which option I will be selecting?

TFS Sidekick 2010 Modules

Once in the Workspace Sidekick, you can filter to find the appropriate Workspace(s) to administer. I searched by username and found three (one is my active Workspace created on the rebuilt development environment, the other two were from old environments that I had never cleaned out). I selected the two obsolete Workspaces and clicked the red X delete icon; done deal, pretty straight forward. Below is a screenshot of the Workspace Sidekick and my remaining active Workspace.

TFS 2010 Workspace Sidekick

jQuery Makes 100% Height So Much Easier

jQuery gets an insane amount of hype these days and for the most part it is warranted. The interesting thing to me is that I never see amazingly new things with jQuery that you couldn’t do with plain old javascript before; however, jQuery just makes it so much easier.

One simple example is the infamous “CSS 100% height” issue. If you’ve done any CSS work, at some point you’ve come across the desire to have a 100% height div or table and have shuffled through all of the hacks and tweaks on how to do this. Often times, the examples use javascript to not only set the height, but also maintain the proper height when resizing the window.

I remember writing client-side code to set the height based on the DOM object height or clientheight and then finding out that it only worked in a particular browser. To maintain the same results across multiple browsers meant an extensive amount of hacky code checking browser type and version.

jQuery to the Rescue

Enter jQuery, where with a single attribute of height() you can abstract all of the difficulty of finding the appropriate height of an object regardless of browser or operating system.

Below, I’ve setup an example of using jQuery to autoset the height of a content div in the middle of the screen. The code also automatically adjusts on resizing the browser window.

Setting Up the HTML

Below is a very basic HTML layout. It consists of a header, a content section, and a footer.

<div id="header">&nbsp;</div>
    
<div id="content">&nbsp;</div>
    
<div id="footer">&nbsp;</div>
        

Add a Bit of CSS

Below, I’ve set the HTML and Body tags to 100% and 0px padding/margin. This allows the javascript method to key off the total height of the HTML element. I’ve also set some colors and fixed heights for the header and footer just for visibility in the demonstration.

html, body
{
    height: 100%;
    padding: 0px;
    margin: 0px;
}
        
#header
{
    background-color: Blue;
    height: 100px;
}
        
#content
{
    background-color: Red;
}
        
#footer
{
    background-color: Blue;
    height: 50px;
}
        

A Short jQuery Snippet

First, we need to discuss the sizeContent() method. This method simply gets the total height of the page via $(“html”).height() and then subtracts the header and footer heights. This gives us the necessary height for the content. We then simply set the CSS height attribute for the content div to the newHeight value.

$(document).ready() and $(window).resize() are pretty self explanatory and simply call the sizeContent() method upon page_load and on any event the window is resized.

//Initial load of page
$(document).ready(sizeContent);

//Every resize of window
$(window).resize(sizeContent);

//Dynamically assign height
function sizeContent() {
    var newHeight = $("html").height() - $("#header").height() - $("#footer").height() + "px";
    $("#content").css("height", newHeight);
}
        

Where to Host My jQuery Web Application?

If you’re looking for a place to host your web application there was recently some interesting news. Web.com made a big move by purchasing Network Solutions for (reports vary) $560 million!

Network Solutions now has VPS hosting (“Virtual Private Server” hosting), for more advanced and technologically-inclined website builders who want more control over their websites, and more capability in the structure they’re using. Head over to Network Solutions to check it out today.

Happy coding!

The Stored Procedure for Searching Challenge

The Problem

You have a table chock full of good business data. This data needs to be accessed by a host of potential search criteria and any combination of that search criteria. What’s the most elegant way to right a stored procedure which accepts multiple parameters as search criteria but only returns the records that relate to the combination of search criteria and accommodates for nulls and empty strings as well.

The Constraints

  • We want search criteria specified to match the record value in field
  • We want empty string to match empty or null records
  • We want null to not include the search criteria in the filter

The Setup

A very basic table to begin with (let’s call it TestingSqlSearchData for consistency):

ID Name
1 Nick
2 John
3 Mary
4 NULL
5 Casey
6  

A Solution (hopefully not “the” solution)

declare @Name varchar(50) = null; --(or 'ni' or '')
	
select * from TestingSqlSearchData
where isnull(Name, '') LIKE 
	(case when @Name = '' then '' else '%' end) + 
	(case when @Name is null then isnull(Name, '') else @Name end) + 
	(case when @Name = '' then '' else '%' end);

This returns the following for each example:

@Name = null

ID Name
1 Nick
2 John
3 Mary
4 NULL
5 Casey
6  

@Name = ‘ni’

ID Name
1 Nick

@Name = ”

ID Name
4 NULL
6  

The Challenge

The challenge is quite simple; we want to demonstrate more elegant solutions to this SQL scenario. You can use any SQL-based approach to accomplish this. If anyone wants to take up the challenge you can submit your solutions (complete with an explanation as to why it is more elegant – as this is not always apparent to everyone else) in the comments below.

P.S. – I really hope to see some comments, so don’t be shy! And, if no one comments, I’ll still leave the post up for at least one solution to this scenario. Who’s going to win bragging rights?

A 30+ Year Old Mythical Man Month

The Mythical Man Month

I recently finished the Mythical Man Month by Frederick Brooks. Many of you have probably heard of Brook’s Law (Adding manpower to a late software project makes it later), and though this is the most popular and lasting theme of the book, additional sections of the writing are still relevant even after more than 30 years. Pause and think about that for a moment, a computer book speaking on the development of mainframe operating systems is relevant today; a time when most twitter remarks are outdated after hours or even minutes.

The book covers the assembly of focused teams, establishing effective roles for team members, how communication becomes the linchpin of a project’s success (which is the basis for why adding manpower can actually cause projects to be delayed even farther).

In addition to some of the interesting team development strategies and project management, there are some great quotes to remember from Mr. Brooks. The following is one in reference to the joys of programming that grabbed my attention:

“The programmer, like the poet, works only slightly removed from pure thought-stuff. He builds his castles in the air, from air, creating by exertion of the imagination. Few media of creation are so flexible, so easy to polish and rework, so readily capable of realizing grand conceptual structures.”

As I read this, it reinforces a development strategy I believe in, which is to have an idea of what you want, but as soon as possible to simply start. In generally, it is inexpensive to start prototyping software. It can be refined, scrapped, re-developed, and of course, there is always the infamous “phase two”. All of this initial work helps define requirements, design architecture, and identify many of the unforeseen difficulties that will happen no matter how much up front planning you do.

If you’re interested in learning more about Brook’s Law and the unique challenges of development projects from the 70’s, check Amazon to pick up your own copy: http://www.amazon.com/Mythical-Man-Month-Software-Engineering-Anniversary/dp/0201835959/ref=sr_1_1?ie=UTF8&qid=1304000450&sr=8-1

Reviving Dependency Walker

If you haven’t noticed, I am a big fan of reviving the fanfare of some of the older development tools that are out there. Of course, there are constantly new tools released to help developers work smarter, faster, and more effectively – but often with all of the excitement over these new tools we forget about old standbys.

Dependency Walker is a tool that when you need it, you really need it. The fact that it is a free, lightweight download which doesn’t require an install to run is just added bonus.

The DLL Problem

We use a third-party DLL in our primary project at work which interacts with Progress. The problem is on a fresh system install and run, you receive the following error:

Could not load file or assembly or one of its dependencies

The dreaded “Could not load file or assembly or one of its dependencies.” The key here is the dependencies portion. I know the Progress.ssl.dll exists and is in the right directory, it compiles correctly, but a dependency inside this DLL is affecting the runtime execution.

How do I know what the dependency is?

Dependency Walker to the Rescue

First, we need to download Dependency Walker – go here: http://dependencywalker.com

Download Dependency Walker

Pick the appropriate version for your OS and take in the great retro-vibe of the website; it shows a little age doesn’t it!

After the download, simply unzip it to any directory on your computer and run depends.exe. Next, open the DLL that you are struggling with (Progress.ssl.dll in my case).

Dependency Walker Inspect DLL

Notice, the popup message and the yellow question marks next to DLL’s which have potential problems. In this particular case, MSVCR71.DLL is the culprit and needed to be copied into a directory in system path.

Here is another screenshot of the error for the DLL’s:

Dependency Walker Error Dependencies

After you’ve attempted to resolve the issue (and this may be different each time based on the particular scenario), refresh Dependency Walker to see if the dependent DLL is corrected or simply try your .NET project again and see if it works properly. In my case, MSVCR71.DLL was all that was needed and we were back on track.

If you have other “tried and true” tools that you still use today, please add them to the comments so we can keep them alive and maybe help a developer out!

Running Zune and WP7 on VirtualBox

I have a fairly unique machine I develop on. I run Ubuntu as my host environment, and run development and office work off of virtual machines through VirtualBox with Windows 7. You may thinks it is a bit crazy but it has some real advantages if you have the patience to work through some of the nuances.

Ubuntu runs around 400 megs of RAM for the host, which compared to Windows 7 is insanely low; it’s quick, light, and stable. My virtual machines perform extremely well on the excess RAM (4 to 8 gigs) per VM and I readily create snapshots whenever installing new software or backing up my system(s). Additionally, I can run dedicated servers as VM’s to test enterprise applications without involving our internal networking resources until we’re ready to deploy to a test/staging environment.

With all of this being said, there are a few things that can drive you crazy; namely, Windows Phone 7 and Zune.

WP7 in VirtualBox

There are several articles on the Internet which discuss how VirtualBox and USB devices work, but here is the cliff-notes version:

USB devices can only be used by either the host or a client VM at any one time. Therefore, to use a USB device (such as WP7), you need to enable it from the VirtualBox Devices drop down (Devices > USB Devices > Unknown Device). Most likely, your device will be displayed as an Unknown Device.

Go ahead and select the device so that it now displays a checkbox next to the device. This should be enough to auto-start the Windows device driver installation which will most likely fail. You can open Device Manager to view the driver which should now be labeled USB Composite Device.

Windows Device Manager Screenshot

The reason this has failed is because by default, VirtualBox does not enable USB 2.0 (EHCI) Controller. You can enable this by opening the Settings for the VM you would like to connect your WP7 to, and selecting the USB tab on the left side. This will allow you to check the appropriate checkbox as seen in the following screenshot:

VirtualBox Enable USB 2.0 Screenshot

If you start the VM from this point you will most likely see the following error:

Oracle VM VirtualBox Extension Pack Required Screenshot

No worries, we simply need to install the Oracle VM VirtualBox Extension Pack to enable USB 2.0 support. I did pause to wonder why you have the ability to select Enable 2.0 USB within the out of the box application, yet it fails at the point of running the VM. It seems this warning could occur as soon as you select the checkbox or simply include the extension pack installation when selecting the checkbox to begin with. Regardless, you can download the extension pack from Oracle (http://www.oracle.com/technetwork/server-storage/virtualbox/downloads/index.html which should look similar to the following screenshot.)

Download VirtualBox Extension Pack Screenshot

After downloading, simply double click the file and you should receive the following prompt:

Install VirtualBox Extension Pack Screenshot

Once you have finished installing, run the VM and select the USB device again. This time, Windows will auto-install the device driver properly and you should receive the following success screen:

Windows Device Auto-Installation Success Screenshot

This may also auto-load Zune and attempt to sync your data for this VM. After completion you should be able to manage content on your phone just as you would a physical installation. Have fun, even busy coders need a bit of music to get through the day!

Running SSMS Under Another Windows Authenticated User


Why do this?

Recently, I’ve been using Ubuntu as a host operating system and running virtual machines for my various development and sandbox server environments. This has led me to not particular want to register all of my client VM’s with our work domain and just pass my credentials when needed. For most applications this works fine; however, with SQL Server Management Studio to login to databases with Windows Authentication it appears you can only use the currently logged in user rather than prompting for credentials.

Can you do this for other applications?

Absolutely, this is basic functionality in the OS; however, since most applications simply prompt for AD credentials instead of binding you to the current logged in local user account, it’s less common than you would think.

Here is the command line:

runas /netonly /user:[domain]\[username] "[ssms_exe_path]"

For example:

runas /netonly /user:workdomain\nbarger "C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe"

P.S. – you can also add this to your Target in the property window of any SSMS icon for convenience.

Tips For Working With Enums

If you use enums frequently throughout code, you may be interested in the following code snippets. The first, is a fairly common extension method I’ve seen for getting descriptions from enum values (this is not my code and unfortunately, I can only site Google as the source).

/// <summary>
/// A collection of extension methods for enums.
/// </summary>
/// <typeparam name="T"></typeparam>
internal static class Enum<T>
{
	/// <summary>
	/// An extension method for enums to get the textual description of a specified enum value.
	/// </summary>
	/// <param name="value"></param>
	/// <returns></returns>
	internal static string GetDescription(T value)
	{
		var da = (DescriptionAttribute[])(typeof(T).GetField(value.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), false));
		return da.Length > 0 ? da[0].Description : value.ToString();
	}

	/// <summary>
	/// An extension method for enums to get the enum by textual description.
	/// </summary>
	/// <param name="value"></param>
	/// <param name="description"></param>
	/// <returns></returns>
	internal static string GetEnumName(Type value, string description)
	{
		FieldInfo[] fis = value.GetFields();
		foreach (FieldInfo fi in fis)
		{
			DescriptionAttribute[] attributes =
			  (DescriptionAttribute[])fi.GetCustomAttributes
			  (typeof(DescriptionAttribute), false);
			if (attributes.Length > 0)
			{
				if (attributes[0].Description == description)
				{
					return fi.Name;
				}
			}
		}
		return description;
	}
}

Samples

Let’s begin by setting up a very basic enum called MyEnum. Don’t forget to add using System.ComponentModel; to your using statements.

public enum MyEnum
{
	[Description("Red")]
	Red = 1,

	[Description("Blue")]
	Blue = 2,

	[Description("Green")]
	Green = 3
}

For the examples, I have created a small console app with the following Main() method:

static void Main(string[] args)
{
	//Setup enum value
	var enumVal = MyEnum.Blue;

	//TODO: Get enum description

	//TODO: Get enum integer

	//TODO: Parse enum from string
}

Get Enum Description

Next, let’s demonstrate how to retrieve the string description associated with the enum value using our new enum extension method.

//Get enum description
Console.WriteLine("Test getting description text from enum");
string enumText = Enum.GetDescription(MyEnum.Blue);
Console.WriteLine(enumText);
Console.ReadKey();

By running the console application, you should get “Blue”.

Get Enum Integer

Next, let’s simply get the integer value associated with the blue enum.

//Get enum integer
Console.WriteLine("Test getting integer from enum");
int enumInt = (int)enumVal;
Console.WriteLine(enumInt);
Console.ReadKey();

After running the console for getting enum integer, you should get “2”.

Parse Enum from String

Finally, let’s get an enum value from a matching string representation. This is actually a parse of string to enum. As a sidenote, if anyone knows of a cleaner way to do this please leave a comment. I’ve never been happy with how wordy and casting this is.

//Parse enum from string
string enumString = "Red";
var enumFromString = (MyEnum)Enum.Parse(typeof(MyEnum), enumString);
Console.WriteLine(enumFromString);
Console.ReadKey();