我如何将这些 "var" 结果分配给不同的变量?

How can i assign these "var" results to different variables?

这些是我的结果:

大家好。

我希望将这些结果分配给不同的变量。

例如;

stringone = "Etiler";
stringtwo = "Kağıthane";
stringthree = "Şişli";

C#是强类型变量必须在编译时定义,所以不能在运行时动态创建变量。 但是,您可以使用集合来保存结果。

使用列表:

var result = db.servis.Where(s => ...).ToList();
// access first element:
var first = result.ElementAt(0);

使用数组:

var result = db.servis.Where(s => ...).ToArray();
// access first element:
var first = result[0]; // here "0" is the array index

使用字典:

var result = db.servis.Where(s => ...)
    .Select((item, index) => new {index, item})
    .ToDictionary(x => "string" + (x.index + 1), x => x.item);
// access first element:
var first = result["string1"]; // here "string1" is the key of the key value pair