Skip to content

Instantly share code, notes, and snippets.

@c4tachan
Created September 12, 2019 15:50
Show Gist options
  • Save c4tachan/e8f5da4c802b45ca50a6b7349c4245a9 to your computer and use it in GitHub Desktop.
Save c4tachan/e8f5da4c802b45ca50a6b7349c4245a9 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
namespace testFirstOrDefault
{
class Program
{
static void Main(string[] args)
{
List<test> testList = new List<test>();
for (int i = 0; i < 4; i++)
{
testList.Add(new test(i, ""));
}
int[] ValsToTest = { 1, 1, 2, 2 };
foreach (int i in ValsToTest)
{
var t = testList.FirstOrDefault(x => x.TestVal == i);
Console.WriteLine("T[{0}].Val = [{1}]!", i, t.Val);
if ("Set!" != t.Val)
{
t.Val = "Set!";
}
}
}
}
internal class test
{
public test(int t, string v)
{
TestVal = t;
Val = v;
}
public int TestVal { get; set; }
public string Val { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment