objective c - Converting ObjC Blocks to C# Lambas -


i need converting objective-c block c#.

here source objc:

nsdate* addyear = [_calendar datebyaddingcomponents:((^{         nsdatecomponents* components = [nsdatecomponents new];         components.month = 12;         return components;     })()) todate:now options:0]; 

now tried following in c#:

nsdate date = _calendar.datebyaddingcomponents((() => {             nsdatecomponents components = new nsdatecomponents();             components.month = 12;             return components;         })(), now, nscalendaroptions.none); 

to following compiler error: expression denotes 'anonymous method' 'method group' expected.

removing parentheses around lambda yields cannot convert 'lambda expression' non-delegate type 'monotouch.foundation.nsdatecomponents'.

what correct c# syntax? need retain closures there lot more in code base porting.

this should work:

        var date = calendar.datebyaddingcomponents (             new nsdatecomponents ()              {                 month = 12             },             nsdate.now,             nscalendaroptions.none); 

edit: might need func:

        func<nsdatecomponents> func = () => new nsdatecomponents () { month = 12 };          date = calendar.datebyaddingcomponents (func (), nsdate.now, nscalendaroptions.none); 

within method:

        date = calendar.datebyaddingcomponents (             (new func<nsdatecomponents>(()=> new nsdatecomponents () { month = 12 }))(),             nsdate.now,             nscalendaroptions.none); 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -