我正在使用ASP.NET Web窗体应用程序.我Client有财产课
public string Id { get; set; }
在一些地方,我需要检查它是否Id实际上是一个guid.例如,我有这个代码:
Guid GuidID;
foreach (Client item in clients)
{
bool isGUID = Guid.TryParse(item.Id, out GuidID);
if (!isGUID)
{
hasExistingClient = true;
}
}
if (hasExistingClient)
{
// Do something...
}
Run Code Online (Sandbox Code Playgroud)
这是一个很多代码,只是为了检查在List<Client> clients(客户端)我是否Client有一个真实Id而不是guid.我想,如果可能的话,让Linq查询出来.就像是
if (clients.Any(c => c.Id is GUID))
Run Code Online (Sandbox Code Playgroud)
但我不知道该写些什么is GUID.
Guid guidID;
bool hasGUID = clients.Any(c => Guid.TryParse(c.Id, out guidID));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1500 次 |
| 最近记录: |