Comparing 2 lists using a flag RRS feed

  • Question

  • Hi, I was talking to a programmer that used to work heavily in Assembly language and was discussing comparing 2 lists,

    he said the following:

    if you loop through the first list and find a file, you then check the second list and if it contains that file you return true. He said you do this by setting a flag. He said it can be done without using IEnumerate or anything like that.

    I am trying to code that idea and struggling.

    Does anyone have an idea how this can be done, it sparked my curiosity so much I've been banging my head against a wall for days.


    each line in each list looks something like this;



    bool hasFile = false;

    foreach(File fileName in list1) { string file = list1.file }

    foreach(File fileName in list2)




    Friday, November 24, 2017 4:44 PM

All replies

  • Why? Why do you need to use assembly language techniques with a language like C#?If you want to learn Assembly language ways to do things then use Assembly language.

    What an Assembly language programmer might call a flag, C# programmers call a Boolean. If more than one state is required then C# has enums.

    Some things that derive from IEnumerate cannot be navigated without IEnumerate. In assembly language the programmer would likely use machine addresses to point to a previous and a next object; if you are unfamiliar with doubly-linked lists then learn about that. Or an assembly language programmer would use an array where there are multiple instances in contiguous locations of memory.

    Sam Hobbs

    Friday, November 24, 2017 5:00 PM
  • To be fair, I had a similar conversation, I believe his point was to not only learn features or syntax of a language but programming itself. He used to program in Assembly languages but is also very good in all c languages etc. He has completed what i asked for previously of which I do not know the answer, just thought I would ask here to see if anyone knows. 

    No disrespect intended towards c-sharp or frustrate anyone with the question.

    Thanks for your feedback.


    Friday, November 24, 2017 5:36 PM
  • The problem is that questions like this are relatively vague; they don't have a clear answer since you are asking how to do something in C# without using the features of C# that are intended to solve the problem. Responses are often subjective; they are a matter of opinion. Questions like this would get stronger criticism in StackOverflow. 

    Sam Hobbs

    Friday, November 24, 2017 6:18 PM
  • StackOverflow is out of control these days, it's not for learners. Exactly the reason I posted the question here where learners are helped rather than stack where they are looked down on.

    When I find out how to solve this little puzzle I asked about I will share it here for anyone who may be interested.

    I understand your point Sam Hobbs and thanks for your input.


    Friday, November 24, 2017 6:26 PM
  • Hi CuriousCoder15,

    According to your description, it seems that you want to compare 2 lists with a flag by using c#. I am not familiar with Assembly language, could you please describe your requirement in detailed.

    If you want to use a flag to store the result of comparing, you could use break method to exit the loop. like this:

    bool hasFile = false;
    foreach(File fileName in list1)
       if(list2.Contains(fileName ))
           hasFile = true;

    If I misunderstand your issue, please feel free let me know.

    Best regards,

    Zhanglong Wu

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Monday, November 27, 2017 7:09 AM