从带有参数的Method返回对象

时间:2019-03-21 17:53:14

标签: c#

我是C#的新手,我没有看到任何清晰的示例说明如何从接受参数的方法返回对象。

    layer.insertSublayer(layer2, at: 1)
    layer.insertSublayer(layer3, at: 2)

1 个答案:

答案 0 :(得分:-1)

假设您的方法是同步的:

public Object LeaderboardRequest(string leaderboard, int entryCount = 50, bool social = false)
{
    object returnObject = null;

    new LeaderboardDataRequest()
        .SetLeaderboardShortCode(leaderboard)
        .SetEntryCount(entryCount)
        .SetSocial(social)
        .Send((response) => {
            if (!response.HasErrors)
            {
                Debug.Log("Found Leaderboard Data...");
                foreach (LeaderboardDataResponse._LeaderboardData entry in response.Data)
                {
                    int rank = (int)entry.Rank;
                    string playerName = entry.UserName;
                    string score = entry.JSONData["SCORE"].ToString();
                    Debug.Log("Rank:" + rank + " Name:" + playerName + " \n Score:" + score);
                }

                returnObject = response.Data;
            }
            else
            {
                Debug.Log("Error Retrieving Leaderboard Data...");
            }
        });

    return returnObject;
}