Statik anonim işlevlerStatic anonymous functions
ÖzetSummary
Lambdalar ve anonim yöntemler üzerinde ' static ' değiştiricisine izin verin; bu, yerel öğeler veya örnek durumunun kapsayan kapsamları yakalamaya izin vermez.Allow a 'static' modifier on lambdas and anonymous methods, which disallows capture of locals or instance state from containing scopes.
MotivasyonMotivation
Kapsayan bağlamdan istenmeden yakalanmaktan kaçının, bu durum yakalanan nesnelerin beklenmedik şekilde bekletilmesine veya beklenmedik ek ayırmalara neden olabilir.Avoid unintentionally capturing state from the enclosing context, which can result in unexpected retention of captured objects or unexpected additional allocations.
Ayrıntılı tasarımDetailed design
Lambda veya anonim yöntem bir static değiştiriciye sahip olabilir.A lambda or anonymous method may have a static modifier. staticDeğiştirici, lambda veya anonim yöntemin statik bir anonim işlev olduğunu belirtir.The static modifier indicates that the lambda or anonymous method is a static anonymous function.
Statik anonim bir işlev kapsayan kapsamdan durum yakalayamaz.A static anonymous function cannot capture state from the enclosing scope.
Sonuç olarak, yerel öğeler, parametreler ve this kapsayan kapsam statik bir anonim işlevde kullanılamaz.As a result, locals, parameters, and this from the enclosing scope are not available within a static anonymous function.
Statik anonim bir işlev örtük veya açık ya da bir başvuruya örnek üyelerine this başvuramaz base .A static anonymous function cannot reference instance members from an implicit or explicit this or base reference.
Statik anonim bir işlev static , kapsayan kapsamdaki üyelere başvurabilir.A static anonymous function may reference static members from the enclosing scope.
Statik anonim bir işlev constant , kapsayan kapsamdaki tanımlara başvurabilir.A static anonymous function may reference constant definitions from the enclosing scope.
nameof() statik bir anonim işlevde , Yereller, parametreler veya this base kapsayan kapsamdan başvuru olabilir.nameof() in a static anonymous function may reference locals, parameters, or this or base from the enclosing scope.
privateKapsayan kapsamdaki Üyeler için erişilebilirlik kuralları, static ve anonim olmayan işlevler için aynıdır static .Accessibility rules for private members in the enclosing scope are the same for static and non-static anonymous functions.
Statik anonim işlev tanımının meta verilerde bir yöntem olarak yayıldığından emin olmak için hiçbir garanti yapılmaz static .No guarantee is made as to whether a static anonymous function definition is emitted as a static method in metadata. Bunu iyileştirmek için derleyici uygulamasına ayrıldınız.This is left up to the compiler implementation to optimize.
Yerel olmayan bir static işlev veya anonim işlev, kapsayan statik bir anonim işlevden durum yakalayabilir ancak kapsayan statik anonim işlev dışında durumu yakalayamaz.A non-static local function or anonymous function can capture state from an enclosing static anonymous function but cannot capture state outside the enclosing static anonymous function.
staticGeçerli bir programdaki adsız bir işlevden değiştiricinin kaldırılması programın anlamını değiştirmez.Removing the static modifier from an anonymous function in a valid program does not change the meaning of the program.