Need Help with Quiz Question.
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Need Help with Quiz Question.

  1. #1
    Join Date
    Apr 2012
    Posts
    2

    Need Help with Quiz Question.

    Hey guys..

    I'm not familiar Microsoft .Net 4.0..
    I need help with this small question:


    One of the implementations below does not improve performance. Which one?




    /Kippers

  2. #2
    Join Date
    Jan 2009
    Posts
    596

    Re: Need Help with Quiz Question.

    If you are not familiar with this feature, why not read up on it? Is this a homework or interview question? If it is, then we can't help without simply giving you the answer.

    But you don't actually need to be familiar with this in order to have a good attempt at answering anyway. I'm not, but one of these options just looks like there is no way it could possibly work in parallel.

  3. #3
    Join Date
    Apr 2012
    Posts
    2

    Re: Need Help with Quiz Question.

    I'm studying electrical engineering, so this language is not so useful for me. I Don't really have the time to learn it, unfortunately.
    Im participating in a competition with me co-students, to win music festival tickets, i need to use my network and solution finding skills in order to answer all the questions, therefore i was hoping that you could simply give me the correct answer..
    Anyways, i found out that the answer was B..

    But now i have gotten a new question, i hope you can help me:




    /Kippers
    Attached Images Attached Images  
    Last edited by Cimperiali; April 17th, 2012 at 08:01 AM. Reason: image attached here

  4. #4
    Join Date
    Jan 2009
    Posts
    596

    Re: Need Help with Quiz Question.

    Quote Originally Posted by Kippers View Post
    I'm studying electrical engineering, so this language is not so useful for me. I Don't really have the time to learn it, unfortunately.
    Im participating in a competition with me co-students, to win music festival tickets, i need to use my network and solution finding skills in order to answer all the questions, therefore i was hoping that you could simply give me the correct answer..
    Anyways, i found out that the answer was B..
    (with highlights in red added by me)

    Yes, B is correct. But you don't actually need to learn this topic in order to answer this question - there is more to 'solution finding skills' than direct knowledge of the topic in question. Before I read this thread, I didn't know anything about PLINQ but I could still answer the question using a bit of logic. This is how I approached it:

    1) The question implies that all four code fragments compile, but one of them will not run in parallel.
    2) With that in mind, assuming 'Parallel.ForEach' does what the name implies (i.e. runs a foreach loop in parallel) then A will run in parallel.
    3) Assuming C and D both compile, they look as if they should do exactly the same thing (just coded in a different style). Therefore these either both run in parallel or neither runs in parallel. As the question says only one answer doesn't, then both must be parallel.
    4) So by a process of elimination, case B must not run in parallel, so is the answer.

    Also, this line (from case B) just looks funny:
    Code:
    foreach (var item in collection.AsParallel())
    Clearly the AsParallel() method is intended to somehow arrange for access to the collection in parallel. But the only way I could imagine this could work would be to then have a further method called on the result of this (as in C and D). Just having it on it's own in the foreach line doesn't seem correct.

    You can see that none of this reasoning requires any more knowledge of this subject than that which is in the question. All it needs is a bit of logic.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center