Created
September 12, 2019 15:50
-
-
Save c4tachan/e8f5da4c802b45ca50a6b7349c4245a9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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