我有一个功能......
var neighbours =
from x in Enumerable.Range(0, array2.GetLength(0))
.Where(x => Math.Abs(x - refx) <= 1)
from y in Enumerable.Range(0, array2.GetLength(1))
.Where(y => Math.Abs(y - refy) <= 1)
select new { x, y };
neighbours.ToList().ForEach(Console.WriteLine);
Run Code Online (Sandbox Code Playgroud)
这个功能运作良好.但我想要:
var neighbours =
from x in Enumerable.Range(0, array2.GetLength(0))
.Where(x => Math.Abs(x - refx) <= 1)
from y in Enumerable.Range(0, array2.GetLength(1))
.Where(y => Math.Abs(y - refy) <= 1)
select new { x, y };
neighbours.ToList().ForEach(label3.Text);
Run Code Online (Sandbox Code Playgroud)
它不起作用.所以,我想将System.Action转换为String ...对此有何看法?
Jon*_*eet 11
您真的不想将操作转换为字符串.你想创造出一个动作做了一个值.我怀疑你可能想要这样的东西:
neighbours.ToList().ForEach(x => label3.Text += x.ToString());
Run Code Online (Sandbox Code Playgroud)
(这很难说,但根据您的示例代码,这是我最好的猜测.)
就字符串连接而言,这非常令人讨厌.也许你想要:
string text = string.Join("\r\n", neighbours);
label3.Text = text;
Run Code Online (Sandbox Code Playgroud)
?
| 归档时间: |
|
| 查看次数: |
1240 次 |
| 最近记录: |