0

At least I think what I'm referring to is a delegate. Here's my scenario

bool allow_login;

StationDC.Load(query, p =>
{
    if (p.Entities.SingleOrDefault(q => q.Category == "Site Status").Value == "Offline") allow_login = false;
    else allow_login = true;

}, true);

I still only barely understand what's actually going on here, but from what I do know the delegate I'm passing to StationDC.Load runs asynchronously, even if on the same thread. I'm confused though that I can access the boolean allow_login since I always thought delegates were more like a separate method, so should be in a different scope. Anyone have some insight as to what's going on under the hood here? How is my boolean persisting to still be around when my delegate is called?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
cost
  • 4,420
  • 8
  • 48
  • 80
  • @KirkWoll ooo Closures. I would say it's technically not a duplicate, if only because I had never heard of closures before today – cost Jul 20 '13 at 23:08
  • still a duplicate. Your question will act as a nice signpost for future googlers. :) – Kirk Woll Jul 20 '13 at 23:10
  • @KirkWoll Indeed! And that also answers my question. I guess my Google-fu wasn't up to this one – cost Jul 20 '13 at 23:11

0 Answers0