Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法从';字符串';至';字符串[]和#x27;与linq一起使用In子句时_C#_Linq_Select_Where Clause_In Clause - Fatal编程技术网

C# 无法从';字符串';至';字符串[]和#x27;与linq一起使用In子句时

C# 无法从';字符串';至';字符串[]和#x27;与linq一起使用In子句时,c#,linq,select,where-clause,in-clause,C#,Linq,Select,Where Clause,In Clause,这是我尝试过的查询,但上面的错误即将出现。 b是逗号分隔的列表。图中显示了b的输出 var CheckInHand = from item in PaymentList where item.Id.In(b) select item.TotalAmt; [图为逗号分隔的列表,为b] [1] :要澄清,中的需要一个字符串[],而您正试图传递b,这是一个字符串 您可以使用将逗号分隔的字符串转换为字符串[]

这是我尝试过的查询,但上面的错误即将出现。 b是逗号分隔的列表。图中显示了b的输出

var CheckInHand = from item in PaymentList
                  where item.Id.In(b)          
                  select item.TotalAmt;
[图为逗号分隔的列表,为b]
[1] :

要澄清,中的
需要一个
字符串[]
,而您正试图传递
b
,这是一个
字符串

您可以使用将逗号分隔的
字符串
转换为
字符串[]


除了@dakota methvin,这可能是相关的

        [Fact]
        public void AssertItem()
        {
            var b = new int[] {311, 306, 299, 303, 304, 302, 301, 291, 281};
            var PaymentList = new Payment[] {new Payment() {Id = 311, TotalAmt = 500}};
            var CheckInHand = from item in PaymentList
                where b.Contains(item.Id)
                select item.TotalAmt.ToString("$##.00");
            Assert.Equal("$500.00",CheckInHand.First());
        }

        public class Payment
        {
            public int TotalAmt { get; set; }
            public int Id { get; set; }
        }

谢谢,它成功了。谢谢。
        [Fact]
        public void AssertItem()
        {
            var b = new int[] {311, 306, 299, 303, 304, 302, 301, 291, 281};
            var PaymentList = new Payment[] {new Payment() {Id = 311, TotalAmt = 500}};
            var CheckInHand = from item in PaymentList
                where b.Contains(item.Id)
                select item.TotalAmt.ToString("$##.00");
            Assert.Equal("$500.00",CheckInHand.First());
        }

        public class Payment
        {
            public int TotalAmt { get; set; }
            public int Id { get; set; }
        }