regarding C# adding objects to list using foreach loop

前端 未结 4 2114
遇见更好的自我
遇见更好的自我 2021-01-06 17:06
foreach (string f in fileName)
{
    if (list.Where(p => p.FileName.Trim().Equals(f.Trim(), StringComparison.OrdinalIgnoreCase)).Count() == 0)
    {
        Serve         


        
4条回答
  •  鱼传尺愫
    2021-01-06 17:51

    Becasue you're adding the same instance each time, just overwriting its properties. You need

    projectfile = new WhateverClassNameProjectFileIs();
    

    at the top of your innermost foreach loop.

提交回复
热议问题