friendsterTalk - Friendster Forum

friendsterTalk - Friendster Forum

Welcome guest! Please Login or Register.

#1  2008-11-11 17:25:17

creamownedz
 active server protocol
creamownedz's display avatar
» FriendsterTalker
PsychoCoder
Class-S
Location: Ftalk & MCTF
Registered: 2008-03-22
Posts: 115
Last visit: Today
Reputation: 7

Retrieve a list of colors in C# [c#]

This snippet takes advantage of the new List< > available to us in C# 2.0 to populate a list of all known colors


Instructions: Make sure to have:

using System.Collections.Generic;
using System.Drawing;


Code:

 private List<string> GetColors()
    {
        //create a generic list of strings
        List<string> colors = new List<string>();
        //get the color names from the Known color enum
        string[] colorNames = Enum.GetNames(typeof(KnownColor));
        //iterate thru each string in the colorNames array
        foreach (string colorName in colorNames)
        {
            //cast the colorName into a KnownColor
            KnownColor knownColor = (KnownColor)Enum.Parse(typeof(KnownColor), colorName);
            //check if the knownColor variable is a System color
            if (knownColor > KnownColor.Transparent)
            {
                //add it to our list
                colors.Add(colorName);
            }
        }
        //return the color list
        return colors;
    }

...Giving of reputation are highly appreciating for me...
Computers don't make errors what they do they do on purpose
...computer is my expertise...
....an addicted coder....
....don't ripp all my tutorials....

Search Friendstertalk

Board footer

FriendsterTalk is not affiliated with Friendster.com
Copyright © 2002–2009 PunBB

[ 11 queries - 0.025 second ]

Pay Per Click Ads by pay per click advertising by Kontera

FriendsterTalk.com x

Welcome to FriendsterTalk! You'll need to login in order to fully use all the features and view all the sections of this site.

Please register if you're not yet a member. =)