---
title: "string till enum"
type: "forum-thread"
url: "https://www.webforum.nu/amne/dotnet/107537-string-till-enum"
topic: ".NET"
topic_url: "https://www.webforum.nu/amne/dotnet"
author: "Dino"
published: "2004-07-17T22:19:24.000Z"
updated: "2004-07-17T22:58:57.000Z"
replies: 2
views: 250
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/dotnet/107537-string-till-enum"
---

# string till enum

## #1 — Dino, 2004-07-17T22:19Z

Hur gör jag för att omvandla ett string värde till ett enum värde

```
<appSettings>
     <add key="BaseType" value="Sand" />
</appSettings>
```

```
enum BaseType : int
{
   Sand,
   Water,
   Earth
}

public static BaseType GetBaseType()
{
   object dbtype = HttpContext.Current.Cache["basetype"];
            
   if(dbtype == null)
   {
      BaseType idbtype = (BaseType)ConfigurationSettings.AppSettings["BaseType"];
      HttpContext.Current.Cache["basetype"] = idbtype;
      return idbtype;                 
   }

   return (BaseType)dbtype;
}
```

Permalänk: https://www.webforum.nu/p/107537

## #2 — renholm, 2004-07-17T22:51Z

Kika på Enum.Parse(Type, string);

Permalänk: https://www.webforum.nu/p/1387797

## #3 — Dino, 2004-07-17T22:58Z

Tackar det löste det. Hade testat med enum.Parse i samma anda som int.Parse. Jaja bara att gå vidare. :)

Permalänk: https://www.webforum.nu/p/1387802

---

Tråden på webben: https://www.webforum.nu/amne/dotnet/107537-string-till-enum
