•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C# section within the Software Development category of DaniWeb, a massive community of 391,901 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,596 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C# advertiser:
Views: 2394 | Replies: 3
![]() |
•
•
Join Date: Jan 2006
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
I'm looking for some help of converting a long to a type enum in something that would be similar to this:
public object ToActionType(Long myval)
{
return (object)((ActionTypes)myval)
}
but the trick is that I don't know the enum just the type of the enum...(I also know for a fact that myval is always part of the enum type t.)
public object ToEnum(Long myval,Type t)
{
return ?????
}
Could somebody explain how to achieve that? :o
public object ToActionType(Long myval)
{
return (object)((ActionTypes)myval)
}
but the trick is that I don't know the enum just the type of the enum...(I also know for a fact that myval is always part of the enum type t.)public object ToEnum(Long myval,Type t)
{
return ?????
}
Could somebody explain how to achieve that? :o
•
•
Join Date: Jan 2006
Location: Its the internet... i am everywhere lol
Posts: 274
Reputation:
Rep Power: 3
Solved Threads: 10
•
•
Join Date: Jan 2006
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
The answer I was looking for was the static function of class Enum...
Enum.ToObject(t,myval)
As specified in the email I didn't know the enum type at the time of call otherwise my first function work perfectly and I wouldn't have a function in the first place.
Thanks anyway for trying to help much appreciated.
Enum.ToObject(t,myval)
As specified in the email I didn't know the enum type at the time of call otherwise my first function work perfectly and I wouldn't have a function in the first place.
Thanks anyway for trying to help much appreciated.
•
•
Join Date: Jan 2006
Location: Its the internet... i am everywhere lol
Posts: 274
Reputation:
Rep Power: 3
Solved Threads: 10
Can you use the string value of the enum instead of the long? You say that you know that myVal is always part of the enum t. so i am assuming you are storing it somewhere. If you could get the string value of the enum for myVal instead then it is a simple case of calling Enum.Parse(t, myValString) which returns an object. Does that help?
if you dont have the string value then you try
string myValString = Enum.GetName(t, myVal);
object theObject = Enum.Parse(t, myValString);
Please ensure you use the Enum not enum.
Hope it helps
if you dont have the string value then you try
string myValString = Enum.GetName(t, myVal);
object theObject = Enum.Parse(t, myValString);
Please ensure you use the Enum not enum.
Hope it helps
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb C# Marketplace
Similar Threads
- converting Enum type from int to char (C)
- C++ Help with enum and cin (C++)
- Having a little trouble with my Code. [please Help me out] (C++)
- reading a file into code (Java)
Other Threads in the C# Forum
- Previous Thread: How to call a perl script in the C# app?
- Next Thread: Copy string into an array


Linear Mode