gpt4 book ai didi

c# - 如何在 C# 中从函数返回结构?

转载 作者:行者123 更新时间:2023-11-30 13:19:39 32 4
gpt4 key购买 nike

我定义了这样一个结构:

 public struct Averages
{
public decimal Sell_GoldOunce = 0;
public decimal Buy_GoldOunce = 0;
public decimal Sell_SilverOunce = 0;
public decimal Buy_SilverOunce = 0;
public int Sell_Mazene = 0;
public int Buy_Mazene = 0;
public int Sell_Gram_18 = 0;
public int Buy_Gram_18 = 0;
public int Sell_Gram_24 = 0;
public int Buy_Gram_24 = 0;
};

现在我想在我的函数中使用它然后返回它

    public (?) AssignValues()// I WANT TO KNOW WHAT SHOULD I PUT INSTITE OF (?)
{
Averages GoldValues;
GoldValues.Sell_GoldOunce = somevalue;
GoldValues.Buy_GoldOunce = somevalue;
GoldValues.Sell_SilverOunce = somevalue;
GoldValues.Buy_SilverOunce = somevalue;
GoldValues.Sell_Mazene = somevalue;
GoldValues.Buy_Mazene = somevalue;
GoldValues.Sell_Gram_24 = somevalue;
GoldValues.Buy_Gram_24 = somevalue;
GoldValues.Sell_Gram_18 = somevalue;
GoldValues.Buy_Gram_18 = somevalue;

return GoldValues;
}

正如我所说,我想知道我应该定义什么样的函数才能返回结构

最佳答案

添加结构的名称:

public Averages AssignValues()
{
Averages GoldValues = new Averages();
GoldValues.Sell_GoldOunce = somevalue;
GoldValues.Buy_GoldOunce = somevalue;
GoldValues.Sell_SilverOunce = somevalue;
GoldValues.Buy_SilverOunce = somevalue;
GoldValues.Sell_Mazene = somevalue;
GoldValues.Buy_Mazene = somevalue;
GoldValues.Sell_Gram_24 = somevalue;
GoldValues.Buy_Gram_24 = somevalue;
GoldValues.Sell_Gram_18 = somevalue;
GoldValues.Buy_Gram_18 = somevalue;

return GoldValues;
}

关于c# - 如何在 C# 中从函数返回结构?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18890152/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com