将<string>转换/转换为List <ulong>

时间:2018-04-14 19:12:12

标签: c# string list casting ulong

我一直在尝试将List<string>属性转换为List<ulong>属性。似乎无论我做什么,它都无法获取或设置数据。

public List<string> _DocumentIds { get; set; } = new List<string>();

我尝试将List<string>转换为List<ulong>的内容:

使用ConvertAll

public List<ulong> DocumentIds 
{ 
  get => _DocumentIds.ConvertAll(x => UInt64.Parse(x)); 
  set => _DocumentIds = value.ConvertAll(x => $"{x}"); 
}

使用演员

public List<ulong> DocumentIds 
{ 
   get => _DocumentIds.Cast<ulong>().ToList(); 
   set => _DocumentIds = value.Cast<string>().ToList(); 
}

使用选择

public List<ulong> DocumentIds
{
   get => _DocumentIds.Select(x => UInt64.Parse(x)).ToList();
   set => _ = value.Select(x => $"{x}").ToList();
}

我不为之骄傲的事

public List<ulong> DocumentIds
{
   get
   {
      var Values = new List<ulong>();
      foreach (var Value in _DocumentIds) Values.Add(UInt64.Parse(Value));
      return Values;
   }
   set => _DocumentIds = value.Cast<string>().ToList();
}

我在get set语句中使用了断点,它总是命中两次但从未命中设置。

0 个答案:

没有答案
相关问题