Linq将枚举与字节进行比较

时间:2015-02-16 14:09:28

标签: c# linq

我有以下LInq声明:

public class TestClass<T> : Form where T: struct, IConvertible
{
    private class MyObject
    {
        public byte Number {get; set;}
        public string Name {get; set;}
    }

    private IReadonlyDictionary<string, T> myListA;
    private List<MyObject> myListB;

    public void Convert()
    {
        var query = (from a in myListA
                     join b in MyListB
                     on a.Value equals b.Number
                     select new
                         {
                             b.Name
                         }).ToList();
    }
}

如何将a.Valueb.Number进行比较?

1 个答案:

答案 0 :(得分:0)

致电ToByte

a.Value.ToByte(Thread.CurrentThread.CurrentCulture) == b.Number

或尝试

Convert.ToByte(a.Value) == b.Number