无法隐式转换类型';字符串';到';EveAI.生活.性格.性格表';

本文关键字:生活 EveAI 性格 字符串 类型 转换 | 更新日期: 2023-09-27 18:26:30

首先,我只是在学习C#,所以我在这里有点力不从心

using EveAI.Live;
using EveAI.Live.Character;
public CharacterSheet CharSheet(string API, int KEY, int USER)
    {
        string Charsname = null;
        CharacterSheet CharSheet = new CharacterSheet();
        EveApi api = new EveApi(KEY, API, USER);
        CharacterSheet csname = api.GetCharacterSheet();
        Charsname = csname.Name;
        return Charsname;
    }

VS正在抛出"return Charsname;"行的错误

提前感谢

无法隐式转换类型';字符串';到';EveAI.生活.性格.性格表';

当您返回作为字符串的csname.Name时,您的方法需要CharacterSheet

我怀疑您可能想更改方法以返回string而不是CharacterSheet。或者返回csname而不是csname.Name

public string CharSheet(string API, int KEY, int USER)
{
    string Charsname = null;
    CharacterSheet CharSheet = new CharacterSheet();
    EveApi api = new EveApi(KEY, API, USER);
    CharacterSheet csname = api.GetCharacterSheet();
    Charsname = csname.Name;
    return Charsname;
}

public CharacterSheet CharSheet(string API, int KEY, int USER)
{
    CharacterSheet CharSheet = new CharacterSheet();
    EveApi api = new EveApi(KEY, API, USER);
    CharacterSheet csname = api.GetCharacterSheet();
    return csname;
}