Click here to Skip to main content
15,891,033 members
Home / Discussions / C#
   

C#

 
AnswerRe: Error While open excel file using Oledb object Pin
Dave Kreskowiak22-Feb-07 15:14
mveDave Kreskowiak22-Feb-07 15:14 
Questionc# Pin
GajendiranVIT22-Feb-07 10:07
GajendiranVIT22-Feb-07 10:07 
AnswerRe: c# Pin
aukh22-Feb-07 11:26
aukh22-Feb-07 11:26 
QuestionConvert State to Abbreviation or Back... Pin
code-frog22-Feb-07 9:48
professionalcode-frog22-Feb-07 9:48 
AnswerRe: Convert State to Abbreviation or Back... Pin
led mike22-Feb-07 9:50
led mike22-Feb-07 9:50 
GeneralRe: Convert State to Abbreviation or Back... Pin
code-frog22-Feb-07 9:53
professionalcode-frog22-Feb-07 9:53 
GeneralRe: Convert State to Abbreviation or Back... Pin
led mike22-Feb-07 9:58
led mike22-Feb-07 9:58 
AnswerRe: Convert State to Abbreviation or Back... Pin
Leslie Sanford22-Feb-07 11:35
Leslie Sanford22-Feb-07 11:35 
Ok, admittedly I got carried away implementing this. The source is from the link led mike provided. Specifically, I used this[^] one.

using System;
using System.Collections.Generic;
 
namespace States
{
    public class StateAbbreviations
    {
        private static readonly Dictionary<string, string> stateAbbreviations = new Dictionary<string, string>();
        private static readonly Dictionary<string, string> stateNames = new Dictionary<string, string>();
 
        static StateAbbreviations()
        {
            stateAbbreviations.Add("ALABAMA", "AL");
            stateAbbreviations.Add("ALASKA", "AK");
            stateAbbreviations.Add("AMERICAN SAMOA", "AS");
            stateAbbreviations.Add("ARIZONA", "AZ");
            stateAbbreviations.Add("ARKANSAS", "AR");
            stateAbbreviations.Add("CALIFORNIA", "CA");
            stateAbbreviations.Add("COLORADO", "CO");
            stateAbbreviations.Add("CONNECTICUT", "CT");
            stateAbbreviations.Add("DELAWARE", "DE");
            stateAbbreviations.Add("DISTRICT OF COLUMBIA", "DC");
            stateAbbreviations.Add("FEDERATED STATES OF MICRONESIA", "FM");
            stateAbbreviations.Add("FLORIDA", "FL");
            stateAbbreviations.Add("GEORGIA", "GA");
            stateAbbreviations.Add("GUAM", "GU");
            stateAbbreviations.Add("HAWAII", "HI");
            stateAbbreviations.Add("IDAHO", "ID");
            stateAbbreviations.Add("ILLINOIS", "IL");
            stateAbbreviations.Add("INDIANA", "IN");
            stateAbbreviations.Add("IOWA", "IA");
            stateAbbreviations.Add("KANSAS", "KS");
            stateAbbreviations.Add("KENTUCKY", "KY");
            stateAbbreviations.Add("LOUISIANA", "LA");
            stateAbbreviations.Add("MAINE", "ME");
            stateAbbreviations.Add("MARSHALL ISLANDS", "MH");
            stateAbbreviations.Add("MARYLAND", "MD");
            stateAbbreviations.Add("MASSACHUSETTS", "MA");
            stateAbbreviations.Add("MICHIGAN", "MI");
            stateAbbreviations.Add("MINNESOTA", "MN");
            stateAbbreviations.Add("MISSISSIPPI", "MS");
            stateAbbreviations.Add("MISSOURI", "MO");
            stateAbbreviations.Add("MONTANA", "MT");
            stateAbbreviations.Add("NEBRASKA", "NE");
            stateAbbreviations.Add("NEVADA", "NV");
            stateAbbreviations.Add("NEW HAMPSHIRE", "NH");
            stateAbbreviations.Add("NEW JERSEY", "NJ");
            stateAbbreviations.Add("NEW MEXICO", "NM");
            stateAbbreviations.Add("NEW YORK", "NY");
            stateAbbreviations.Add("NORTH CAROLINA", "NC");
            stateAbbreviations.Add("NORTH DAKOTA", "ND");
            stateAbbreviations.Add("NORTHERN MARIANA ISLANDS", "MP");
            stateAbbreviations.Add("OHIO", "OH");
            stateAbbreviations.Add("OKLAHOMA", "OK");
            stateAbbreviations.Add("OREGON", "OR");
            stateAbbreviations.Add("PALAU", "PW");
            stateAbbreviations.Add("PENNSYLVANIA", "PA");
            stateAbbreviations.Add("PUERTO RICO", "PR");
            stateAbbreviations.Add("RHODE ISLAND", "RI");
            stateAbbreviations.Add("SOUTH CAROLINA", "SC");
            stateAbbreviations.Add("SOUTH DAKOTA", "SD");
            stateAbbreviations.Add("TENNESSEE", "TN");
            stateAbbreviations.Add("TEXAS", "TX");
            stateAbbreviations.Add("UTAH", "UT");
            stateAbbreviations.Add("VERMONT", "VT");
            stateAbbreviations.Add("VIRGIN ISLANDS", "VI");
            stateAbbreviations.Add("VIRGINIA", "VA");
            stateAbbreviations.Add("WASHINGTON", "WA");
            stateAbbreviations.Add("WEST VIRGINIA", "WV");
            stateAbbreviations.Add("WISCONSIN", "WI");
            stateAbbreviations.Add("WYOMING", "WY");
 
            foreach(KeyValuePair<string, string> pair in stateAbbreviations)
            {
                stateNames.Add(pair.Value, pair.Key);
            }
        }
 
        public static string GetStateName(string stateAbbreviation)
        {
            string name;
 
            if(stateAbbreviation == null)
            {
                throw new ArgumentNullException("State abbreviation cannot be null");
            }
            else 
            {
                if(!stateNames.TryGetValue(stateAbbreviation.ToUpper(), out name))
                {
                    throw new ArgumentException("Unknown abbreviation");
                }
            }
 
            return name;
        }
 
        public static string GetStateAbbreviation(string stateName)
        {
            string abbreviation;
 
            if(stateName == null)
            {
                throw new ArgumentNullException("State name cannot be null");
            }
            else
            {
                if(!stateAbbreviations.TryGetValue(stateName.ToUpper(), out abbreviation))
                {
                    throw new ArgumentException("Unknown state");
                }
            }
 
            return abbreviation;
        }
 
        public static IEnumerable<string> Abbreviations
        {
            get
            {
                return stateAbbreviations.Values;
            }
        }
 
        public static IEnumerable<string> Names
        {
            get
            {
                return stateNames.Values;
            }
        }
    }
}


Some driver code:

using System;
using System.Collections.Generic;
using System.Text;
 
namespace States
{
    class Program
    {
        static void Main(string[] args)
        {
            foreach(string name in StateAbbreviations.Names)
            {
                Console.WriteLine(StateAbbreviations.GetStateAbbreviation(name));
            }
 
            Console.WriteLine();
 
            foreach(string abbreviaton in StateAbbreviations.Abbreviations)
            {
                Console.WriteLine(StateAbbreviations.GetStateName(abbreviaton));
            }
 
            Console.Read();
        }
    }
}


Written just for fun. Use at your own risk. Smile | :)
GeneralTwo Things... Pin
code-frog22-Feb-07 11:51
professionalcode-frog22-Feb-07 11:51 
GeneralRe: Two Things... Pin
Leslie Sanford22-Feb-07 12:09
Leslie Sanford22-Feb-07 12:09 
GeneralRe: Convert State to Abbreviation or Back... Pin
Guffa22-Feb-07 12:10
Guffa22-Feb-07 12:10 
GeneralRe: Convert State to Abbreviation or Back... Pin
code-frog22-Feb-07 12:11
professionalcode-frog22-Feb-07 12:11 
Questionrefer to control on aspx page from ascx control Pin
digsy_22-Feb-07 8:49
digsy_22-Feb-07 8:49 
AnswerRe: refer to control on aspx page from ascx control Pin
Abisodun22-Feb-07 9:41
Abisodun22-Feb-07 9:41 
Questionconverting 24bits image into 8 bit grayscale image Pin
haseeb_saeed22-Feb-07 8:22
haseeb_saeed22-Feb-07 8:22 
AnswerRe: converting 24bits image into 8 bit grayscale image Pin
Ed.Poore22-Feb-07 8:37
Ed.Poore22-Feb-07 8:37 
AnswerRe: converting 24bits image into 8 bit grayscale image Pin
Dan Neely22-Feb-07 8:55
Dan Neely22-Feb-07 8:55 
GeneralRe: converting 24bits image into 8 bit grayscale image Pin
haseeb_saeed22-Feb-07 23:09
haseeb_saeed22-Feb-07 23:09 
GeneralRe: converting 24bits image into 8 bit grayscale image Pin
Dan Neely23-Feb-07 2:10
Dan Neely23-Feb-07 2:10 
AnswerRe: converting 24bits image into 8 bit grayscale image Pin
Christian Graus22-Feb-07 13:42
protectorChristian Graus22-Feb-07 13:42 
GeneralRe: converting 24bits image into 8 bit grayscale image Pin
haseeb_saeed22-Feb-07 23:01
haseeb_saeed22-Feb-07 23:01 
Questionconverting 24bits image into 8 bit grayscale image Pin
haseeb_saeed22-Feb-07 8:21
haseeb_saeed22-Feb-07 8:21 
QuestionAdding web service reference in Visual Studio Pin
Jaguas22-Feb-07 8:06
Jaguas22-Feb-07 8:06 
AnswerRe: Adding web service reference in Visual Studio Pin
Michael Sync22-Feb-07 16:21
Michael Sync22-Feb-07 16:21 
GeneralRe: Adding web service reference in Visual Studio Pin
mail57235222-Feb-07 23:45
mail57235222-Feb-07 23:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.