我如何解决不能隐式转换类型'Mis.Framework.Status'到'字符串'。 [英] How Do I Solve Cannot Implicitly Convert Type 'Mis.Framework.Status' To 'String'.
本文介绍了我如何解决不能隐式转换类型'Mis.Framework.Status'到'字符串'。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
HEllo团队,
i我很困惑。请指导我
我有
while (oReader.Read())
{
customClearance.Status =(Status)Enum.Parse( typeof (状态),oReader [ STATUS]的ToString());
}
在数据库中,列状态
是 Varchar(20)
数据类型。
在MIS.Framework类中。
i有Enum如下:
public enum 状态
{
N,
Y,
W,
S,
E,
R
}
i我收到的错误如下:
无法将类型'MIS.Framework.Status'隐式转换为'string'。
如何解决此错误?.Kindly指导我
谢谢
Harshal Raut
解决方案
嗯,枚举的基础值类型,默认为int
。所以你也可以使用int值来访问你的枚举。
如果你想改变这个枚举的类型,那么你必须指定它明确。
看一些例子: C#中的字符串枚举 [ ^ ]
http://weblogs.asp.net/stefansedich/ archive / 2008/03/12 / enum-with-string-values-in-c.aspx [ ^ ]。
解决问题的方法是,解析int 中的字符串! :)
-KR
让我们做一些实验:
int sta1 = Status.N;
int sta2 = Status.R;
Console.WriteLine( N = {0} R = {1},sta1 ,sta2);
详情请见:enum(C#参考) [ ^ ]并按照所有相关文章进行操作。
customClearance.Status = System。 Convert.ToChar(oReader [ STATUS]);
HEllo Team,
i am getting confused .Please guide me
I have
while (oReader.Read())
{
customClearance.Status = (Status)Enum.Parse(typeof(Status), oReader["STATUS"].ToString());
}
In Database, Column Status
is Varchar(20)
data type.
In MIS.Framework Class.
i have Enum as follow:
public enum Status
{
N,
Y,
W,
S,
E,
R
}
i am getting the error as follows :
Cannot implicitly convert type 'MIS.Framework.Status' to 'string'.
How to solve this error?.Kindly Guide me
Thanks
Harshal Raut
解决方案
Well, the underlying value type of enum, by default isint
. So you can access your enum using int values as well.
If you want to change the type of this enum, then you must specify it explicity.
Look at some example : String Enumerations in C#[^]
http://weblogs.asp.net/stefansedich/archive/2008/03/12/enum-with-string-values-in-c.aspx[^].
And the solution towards your problem is, parse the string in int ! :)
-KR
Let's do some experiment:
int sta1 = Status.N; int sta2 = Status.R; Console.WriteLine("N={0} R={1}", sta1, sta2);
For further information, please see: enum (C# Reference)[^] and follow all related articles.
customClearance.Status = System.Convert.ToChar(oReader["STATUS"]);
这篇关于我如何解决不能隐式转换类型'Mis.Framework.Status'到'字符串'。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文