我有2个对象数组。我需要将其中一个对象值添加到名称匹配的第二个数组中。使用最少的代码执行此操作的最有效方法是什么?
firstArray = [
{name: "Henry", balance: 2176.90, Age: 26},
{name: "Jon", balance: 122.10, Age: 31},
{name: "Dave", balance: 258.23, Age: 42},
{name: "Tom", balance: 591.00, Age: 19},
{name: "Mary", balance: 12.54, Age: 56},
{name: "Rick", balance: 5287.25, Age: 29},
{name: "Jane", balance: 6527.20, Age: 24}
]
secondArray = [
{user: "Henry", city: "New York", dept: "Sales"},
{user: "Vanessa", city: "New York", dept: "Sales"},
{user: "Susan", city: "Dallas", dept: "Marketing"},
{user: "Jon", city: "New York", dept: "Management"},
{user: "Dave", city: "Dallas", dept: "Marketing"}
{user: "Jay", city: "Spokane", dept: "IT"}
]
secondArray = [
{user: "Henry", city: "New York", dept: "Sales", balance: 2176.90},
{user: "Vanessa", city: "New York", dept: "Sales", balance: "N/A"},
{user: "Susan", city: "Dallas", dept: "Marketing", balance: "N/A"},
{user: "Jon", city: "New York", dept: "Management", balance: 122.10},
{user: "Dave", city: "Dallas", dept: "Marketing", balance: 258.23}
{user: "Jay", city: "Spokane", dept: "IT", balance: 591.00}
]
答案 0 :(得分:0)
你需要遍历数组,没有更有效的方法来处理它。
private void button1_Click(object sender, EventArgs e)
{
DataGridViewImageColumn imageColumn = new DataGridViewImageColumn();
DataGridViewImageCell imageCell = new DataGridViewImageCell();
Bitmap bmpImage = null;
int number_of_rows = dgv_resultats.RowCount;
for (int i = 0; i < number_of_rows-1; i++)
{
//bmpImage = (Bitmap)Image.FromFile(Application.StartupPath + dgv_resultats.Rows[1].Cells[1].Value.ToString(), true);
bmpImage = (Bitmap)Image.FromFile(@"D:\LigueStats\Data\Logo\Ligue 1\EST.png", true);
imageColumn.Image = bmpImage;
imageColumn.ImageLayout = DataGridViewImageCellLayout.Stretch;
dgv_resultats.Rows[i].Cells["logo_dom"].Value = bmpImage;
}
}