Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8515961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:17:21+00:00 2026-06-11T05:17:21+00:00

This is possibly a silly question, but do I need to use and assignment

  • 0

This is possibly a silly question, but do I need to use and assignment with a lock, or can I simply return the results.

For example:

I have a private helper method that returns an IEnumerable list of file names. It uses a lock to ensure the method is thread safe while it is iterating around the m_transfers collection.

Do I need an assignment…

IEnumerable<String> updated;
lock (m_transfers.Lock)
{
    updated = m_transfers.Values.Where(transfer => transfer.Updated)
                         .Select(transfer => transfer.Filename);
}
return updated;

Or can I just do

lock (m_transfers.Lock)
{
    return updated = m_transfers.Values.Where(transfer => transfer.Updated)
                            .Select(transfer => transfer.Filename);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T05:17:23+00:00Added an answer on June 11, 2026 at 5:17 am

    No, you don’t need to add an extra variable; the semantic is the same either way, since in either case we only actually return the value once we have relinquished the lock.

    Since the variable doesn’t serve a purpose, I would remove it and use the second version – although technically, the compiler actually puts it back in anyway (a lock involves a try/finally, and at the IL level you can’t ret from inside a try; so the compiler actually writes it like your first version).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This maybe a silly question, but I need confirmation and I have no one
My question may be silly, but I need to use a library from its
It can this is a silly question, but is it possible to handle files
This might seems silly question but for me it is annoying. I have installed
This may be a silly question, but I can't figure out the correct syntax
It this possible? How? (Maybe silly question, but I couldn't find answer :( )
This is quite possibly a very stupid question but I've tried searching for and
I don't understand how this example can possibly work: double * GetSalary() { double
I have a very complicated issue, but if I can do this, then I
This question is just something that I have been thinking about lately. Can a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.