0

my code is like this:

    dt1 = dt1
            .AsEnumerable()
            .Where(r=>!String.IsNullOrEmpty(r.Field<string>("Transaction_x0020_Type"))
                        &&(r.Field<string>("Transaction_x0020_Type").ToLower().Contains(YrStrList[0].ToLower())
                        ||r.Field<string>("Transaction_x0020_Type").ToLower().Contains(YrStrList[1].ToLower())
                        ||r.Field<string>("Transaction_x0020_Type").ToLower().Contains(YrStrList[2].ToLower())
                        ||r.Field<string>("Transaction_x0020_Type").ToLower().Contains(YrStrList[3].ToLower())))
            .AsDataView()
            .ToTable();

and I hope can put the following part in a loop:

     &&(r.Field<string>("Transaction_x0020_Type").ToLower().Contains(YrStrList[0].ToLower())
                        ||r.Field<string>("Transaction_x0020_Type").ToLower().Contains(YrStrList[1].ToLower())
                        ||r.Field<string>("Transaction_x0020_Type").ToLower().Contains(YrStrList[2].ToLower())
                        ||r.Field<string>("Transaction_x0020_Type").ToLower().Contains(YrStrList[3].ToLower())))
4
  • what are you trying to accomplish by putting that code into a loop? Commented May 27, 2014 at 16:18
  • Why loop when linq is already looping for you? Commented May 27, 2014 at 16:19
  • "Thanks" at the bottom of the post is not necessary and is frowned upon by the community. Adding it as an edit (and the only change in the edit!) is definitely not needed/appropriate. I have rolled the change back for you. Commented May 27, 2014 at 16:21
  • A bit of an explanation of what you are trying to accomplish would make a good edit though... Commented May 27, 2014 at 16:22

1 Answer 1

1

Assuming you're checking all values in YrStrList and not just the first 4 (of possibly more than 4):

&&(YrStrList.Any(y => r.Field<string>("Transaction_x0020_Type")
                       .ToLower()
                       .Contains(y.ToLower())))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.