Variable Scoping in Anonymous Delegates in C#

Posted by: Rick Strahls WebLog, on 27 Apr 2008 | View original | Bookmarked: 0 time(s)

Every once in a while when I write code that deals with Anonymous Delegates, I still kinda freak out when it comes to the behavior of closures and the variable scoping that goes along with it. For example, the following code uses a List<T>.Find() Predicate to search for items in the list and requires that a dynamic value is compared to: public void AddScript(ScriptItem script){    ScriptItem match = null;     // *** Grab just the path    if...

Advertisement
Free Agile Project Management Tool from Telerik
TeamPulse Community Edition helps your team effectively capture requirements, manage project plans, assign and track work, and most importantly, be continually connected with each other.
Category: C# | Other Posts: View all posts by this blogger | Report as irrelevant | View bloggers stats | Views: 799 | Hits: 47

Similar Posts

  • A deadlock was detected while trying to lock variables more
  • Anonymous Methods vs Threads more
  • BizTalk Server 2006: An xpath() Function problem more
  • Generating a Field and its Property Using Resharper Live Templates more
  • Local variables: scope vs. lifetime (plus closures) more

News Categories

.NET | Agile | Ajax | Architecture | ASP.NET | BizTalk | C# | Certification | Data | DataGrid | DataSet | Debugger | DotNetNuke | Events | GridView | IIS | Indigo | JavaScript | Mobile | Mono | Patterns and Practices | Performance | Podcast | Refactor | Regex | Security | Sharepoint | Silverlight | Smart Client Applications | Software | SQL | VB.NET | Visual Studio | W3 | WCF | WinFx | WPF | WSE | XAML | XLinq | XML | XSD