Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 有没有一种方法可以;注入;方法中点后的变量,例如Console.variableLine();_C# - Fatal编程技术网

C# 有没有一种方法可以;注入;方法中点后的变量,例如Console.variableLine();

C# 有没有一种方法可以;注入;方法中点后的变量,例如Console.variableLine();,c#,C#,我想把euw变成一个变量。像这样 var summoner = api.GetSummoner(Region.euw, "AlexK"); 另一个例子是 Console.WriteLine("Type your server") //and I type for example one of the following (eune,euw,na) string server = Console.ReadLine(); var summoner = api.GetSummoner(Reg

我想把euw变成一个变量。像这样

var summoner = api.GetSummoner(Region.euw, "AlexK");    
另一个例子是

Console.WriteLine("Type your server") //and I type for example one of the following (eune,euw,na)
string server = Console.ReadLine();
var summoner = api.GetSummoner(Region.server, "AlexK");
我使用的C#包装就是这个。
我对C#so ELI5或发送一些链接相当陌生。
提前感谢。

根据点运算符后面的内容,必须以不同的方式处理

如果要基于输入调用方法,可以。但是,除非您处理的是未知类型(当方法名称仅在运行时已知),否则最好使用
if
语句对代码进行分支

Console.WriteLine("Type if you want to Read or Write");
string preference = Console.ReadLine();
Console.preferenceLine() //There is no practical use for this one just giving an example of where I want to place the variable.
这与枚举不同,枚举是一种完全不同的语言结构,可以轻松地从文本中解析

if (method == "read")
{
    string input = Console.ReadLine();
    var summoner = api.GetSummoner(server, "AlexK");
    // TODO: do something with the summoner
}
if (method == "write")
{
    Console.WriteLine("Printing data:")
    // TODO: print data
}
根据点运算符后面的内容,必须以不同的方式处理

如果要基于输入调用方法,可以。但是,除非您处理的是未知类型(当方法名称仅在运行时已知),否则最好使用
if
语句对代码进行分支

Console.WriteLine("Type if you want to Read or Write");
string preference = Console.ReadLine();
Console.preferenceLine() //There is no practical use for this one just giving an example of where I want to place the variable.
这与枚举不同,枚举是一种完全不同的语言结构,可以轻松地从文本中解析

if (method == "read")
{
    string input = Console.ReadLine();
    var summoner = api.GetSummoner(server, "AlexK");
    // TODO: do something with the summoner
}
if (method == "write")
{
    Console.WriteLine("Printing data:")
    // TODO: print data
}

不,没有办法做到这一点,老实说,如果可能的话,我不知道为什么它会有用。也许你想研究什么是数组或字典,因为我的盲目猜测是,这些概念可能是XY问题中的Y。在C#中不是。在第一个例子中,更改值EUW的唯一真正方法是在代码中进行。您无法获取用户输入。将它存储在一个变量中,并根据他的答案进行更改。不,没有办法做到这一点,老实说,如果可能的话,我不知道为什么它会有用。也许你想研究什么是数组或字典,因为我的盲目猜测是,这些概念可能是XY问题中的Y。在C#中不是。在第一个例子中,更改值EUW的唯一真正方法是在代码中进行。您无法获取用户输入。将其存储在变量中,并根据他的答案进行更改。