該集合可以自訂該屬性名稱
Code:
using System; using System.Windows.Forms; using System.Linq; namespace Sample { public partial class Form1 : Form { String[] names = { "a", "b", "c", "d", "e","f","g","h" }; public Form1() { InitializeComponent(); var gp = from n in names select new { name = n, index = Array.FindIndex(names, f => f.Contains(n)) }; foreach (var g in gp) textBox1.Text += String.Format("{0}={1}{2}", g.index, g.name, Environment.NewLine); } } }
執行結果: