if (dialog.ShowDialog() == true) { if (Building?.FileNames != null) { foreach (var item in dialog.FileNames) { if ((bool)(Building?.FileNames?.Any(File => File.FullPath==item))) { MessageBox.Show("item existed! "); } else { File newfile = new File() { FileName = System.IO.Path.GetFileName(item), FullPath = System.IO.Path.GetFullPath(item) }; Building?.FileNames?.Add(newfile); } } } MessageBox.Show($"items {Building?.ImagePaths?.Count}"); }