C# 使用C将列表转换为数组#
我正在尝试转换从API提取的列表,并将其转换为列表。该列表确实返回其他数据,但我在其中有代码可以返回我想要的数据(可能是错误的)C# 使用C将列表转换为数组#,c#,C#,我正在尝试转换从API提取的列表,并将其转换为列表。该列表确实返回其他数据,但我在其中有代码可以返回我想要的数据(可能是错误的) //这会提取数据 公共列表CorpAccounts(int CORP_KEY、string CORP_API、int USER) { 列表_CAccount=新列表(); EveApi=新的EveApi(公司密钥、公司api、用户); List caccount=api.GetCorporationAccountBalance(); foreach(caccount中
//这会提取数据
公共列表CorpAccounts(int CORP_KEY、string CORP_API、int USER)
{
列表_CAccount=新列表();
EveApi=新的EveApi(公司密钥、公司api、用户);
List caccount=api.GetCorporationAccountBalance();
foreach(caccount中的var行)
{
//之后的每一件事
字符串apiString=line.ToString();
string[]tokens=apitstring.Split(“”);
_CAccount.Add(行);
}
返回计数;
}
//我正在尝试将列表转换为数组
私人帐户()
{
字符串[]corpbal=cwaa.CorpAccounts(CORP_KEY,CORP_API,USER).ToArray();
}
使用该代码,我得到以下错误:
错误1无法隐式转换类型“EveAI.Live.AccountBalance[]”
至“字符串[]”
我不知道我做错了什么 List.ToArray
方法()
语法:
公共T[]ToArray()
因此,如果您有列表):
List.ToArray
Method()
语法:
公共T[]ToArray()
因此,如果您有列表):
您正试图将AccountBalance[]
分配到string[]
-如错误所示
除非您确实需要string[]
,否则应将变量声明更改为AccountBalance[]
:
private void docorpaccounts()
{
AccountBalance[] corpbal = cwaa.CorpAccounts(CORP_KEY, CORP_API, USER).ToArray();
}
或者指定如何将帐户余额
转换为字符串
。e、 g.使用ToString
方法:
private void docorpaccounts()
{
string[] corpbal = cwaa.CorpAccounts(CORP_KEY, CORP_API, USER)
.Select(x => x.ToString())
.ToArray();
}
或者它的一个属性
private void docorpaccounts()
{
string[] corpbal = cwaa.CorpAccounts(CORP_KEY, CORP_API, USER)
.Select(x => x.MyStringProperty)
.ToArray();
}
您正试图将AccountBalance[]
分配到string[]
-如错误所示
除非您确实需要string[]
,否则应将变量声明更改为AccountBalance[]
:
private void docorpaccounts()
{
AccountBalance[] corpbal = cwaa.CorpAccounts(CORP_KEY, CORP_API, USER).ToArray();
}
或者指定如何将帐户余额
转换为字符串
。e、 g.使用ToString
方法:
private void docorpaccounts()
{
string[] corpbal = cwaa.CorpAccounts(CORP_KEY, CORP_API, USER)
.Select(x => x.ToString())
.ToArray();
}
或者它的一个属性
private void docorpaccounts()
{
string[] corpbal = cwaa.CorpAccounts(CORP_KEY, CORP_API, USER)
.Select(x => x.MyStringProperty)
.ToArray();
}
或者只使用var
让类型推断工作,这是你对这类事情的神奇和抽象思考。或者只使用var
让类型推断工作,这是你对这类事情的神奇和抽象思考。错误是自我描述,你需要AccountBalance[]
而不是string[]
。我认为要解决您的问题,您需要更改列表\u CAccount=new List()代码>到列表_CAccount=新列表()代码>。以及public List CorpAccounts()
到public List CorpAccounts
。这是解决问题的一种方法数组类型必须与列表类型匹配。错误是自我描述,您需要AccountBalance[]
而不是string[]
。我认为要解决问题,您需要更改list\u CAccount=new list()代码>到列表_CAccount=新列表()代码>。以及public List CorpAccounts()
到public List CorpAccounts
。这是解决问题的一种方法数组类型必须与列表类型匹配。