Been trying to figure out how i can get "sum" and "reg" to go throughout the whole application without the user having to continually Input. (sorry im bad at explaining stuff so go easy on me please)
using RiotSharp;
using RiotSharp.Misc;
using RiotSharp.SummonerEndpoint;
namespace WindowsFormsApp3
{
public partial class Form1 : Form
{
private static RiotApi api = ("nolooky");
public string sum;
public string reg;
public void sumShit()
{
reg = sumReg.Text;
sum = sumInput.Text;
try
{
if (reg == "")
{
}
else if (sum == "")
{
errLabel.Text = "PLEASE INSERT SUMMONER NAME!";
errLabel.ForeColor = System.Drawing.Color.OrangeRed;
}
else if (reg == "OCE" && sum != null)
{
var regOCE = RiotSharp.Misc.Region.oce;
var summoner = api.GetSummonerByName(regOCE, sum);
MessageBox.Show(summoner.Id.ToString());
}
else if (reg == "NA" && sum != null)
{
var regNA = RiotSharp.Misc.Region.na;
}
return;
}
catch (RiotSharpException)
{
errLabel.Text = "SUMMONER NOT FOUND!";
errLabel.ForeColor = System.Drawing.Color.OrangeRed;
}
}
}
}
i wanna be able to use the summoner.Id in different voids but it just doesn't let me. Again sorry for the bad explanation. But thanks for your help.
答案 0 :(得分:0)
我不确定我理解你想要什么,但我认为您可以使用summoner
作为静态字段创建类,并且您可以在整个应用程序中调用summoner
作为ClassName .summoner(但在使用之前一定要给summoner
一个值)。
答案 1 :(得分:0)
有很多方法可以实现这一目标。其中一种方式,声明它已声明reg
public string reg;
public object summoner;
并使用相同的
else if (reg == "OCE" && sum != null)
{
var regOCE = RiotSharp.Misc.Region.oce;
summoner = api.GetSummonerByName(regOCE, sum);
MessageBox.Show(summoner.Id.ToString());
}
现在,您可以在整个代码中的任何位置使用召唤师。
注意:由于装箱和拆箱而涉及开销,因为它不清楚你的api返回的类型是什么。如果您知道确切的类型,请将其替换为object关键字。