简体   繁体   中英

Cannot implicitly Convert Type string to

This is the code which i am using..

using PWServiceProxy

PortfolioQueryOptions Query = new PortfolioQueryOptions();
Query.PortfolioTypes = "Funded";

I am receiving an error such as

Cannot implicitly convert type string to PWServiceProxy.PortfolioTypes.

Seems that Query.PortfolioTypes is type of PWServiceProxy.PortfolioTypes ie enum .

So you need to

Query.PortfolioTypes = PortfolioTypes.Funded;

or

string str = "Funded"; // or something else
PortfolioTypes pt;
if (Enum.TryParse(str, out pt))
    Query.PortfolioTypes = pt;
else
    throw new Exception("Can't parse input as PortfolioTypes");

假设PortfolioTypes是一个名为YourEnumTypeenumYourEnumType尝试以下操作:

Query.PortfolioTypes = (YourEnumType) Enum.Parse(typeof(YourEnumType), "Funded", true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM