{"id":113,"date":"2006-10-06T18:00:50","date_gmt":"2006-10-06T16:00:50","guid":{"rendered":"http:\/\/www.forksoft.de\/blog\/2006\/10\/06\/lambda-operator-c-30\/"},"modified":"2008-10-12T13:34:23","modified_gmt":"2008-10-12T11:34:23","slug":"lambda-operator-c-30","status":"publish","type":"post","link":"http:\/\/www.navision-blog.de\/blog\/2006\/10\/06\/lambda-operator-c-30\/","title":{"rendered":"Lambda Operator C# 3.0"},"content":{"rendered":"<p>Delegates gibt es schon in C#, aber mit dem Lambda Operator (=&gt;) geht das  nun k&#252;rzer.<\/p>\n<p>Folgendes generisches Beispiel (bisher):<\/p>\n<div class=\"synthi_code\" style=\"display:none;\" id =\"plain_synthi_6ab2aefaa479d\">\n<div class=\"synthi_header\" style=\"font-weight:bold;\"> CSharp <span  class=\"synthi_button\"style=\"font-weight:lighter;font-size:smaller;\">[<a href=\"#\" onClick=\"javascript:document.getElementById('styled_synthi_6ab2aefaa479d').style.display='block';document.getElementById('plain_synthi_6ab2aefaa479d').style.display='none';return false\">Show Styled Code<\/a>]:<\/span><\/div>\n<pre style=\"width:100%;overflow:auto;\">delegate T Func(T t);\r\nFunc  funcDel = delegate(int x)\r\n{\r\nreturn x + x;\r\n}\r\nConsole.WriteLine(funcDel(5));<\/pre>\n<\/div>\n<div class=\"synthi_code\" style=\"display:block;\" id =\"styled_synthi_6ab2aefaa479d\">\n<div class=\"synthi_header\" style=\"font-weight:bold;\"> CSharp <span  class=\"synthi_button\"style=\"font-weight:lighter;font-size:smaller;\">[<a href=\"#\" onClick=\"javascript:document.getElementById('plain_synthi_6ab2aefaa479d').style.display='block';document.getElementById('styled_synthi_6ab2aefaa479d').style.display='none';return false\">Show Plain Code<\/a>]:<\/span><\/div>\n<div class=\"csharp\" style=\"font-family: monospace;\">\n<ol>\n<li style=\"font-weight: bold;\">\n<div style=\"font-family: 'Courier New', Courier, monospace; font-weight: normal;\"><span style=\"color: #FF0000;\">delegate<\/span> T Func<span style=\"color: #000000;\">&#40;<\/span>T t<span style=\"color: #000000;\">&#41;<\/span>;<\/div>\n<\/li>\n<li style=\"font-weight: bold;\">\n<div style=\"font-family: 'Courier New', Courier, monospace; font-weight: normal;\">Func&nbsp; funcDel = <span style=\"color: #FF0000;\">delegate<\/span><span style=\"color: #000000;\">&#40;<\/span><span style=\"color: #FF0000;\">int<\/span> x<span style=\"color: #000000;\">&#41;<\/span><\/div>\n<\/li>\n<li style=\"font-weight: bold;\">\n<div style=\"font-family: 'Courier New', Courier, monospace; font-weight: normal;\"><span style=\"color: #000000;\">&#123;<\/span><\/div>\n<\/li>\n<li style=\"font-weight: bold;\">\n<div style=\"font-family: 'Courier New', Courier, monospace; font-weight: normal;\"><span style=\"color: #0600FF;\">return<\/span> x + x;<\/div>\n<\/li>\n<li style=\"font-weight: bold;\">\n<div style=\"font-family: 'Courier New', Courier, monospace; font-weight: normal;\"><span style=\"color: #000000;\">&#125;<\/span><\/div>\n<\/li>\n<li style=\"font-weight: bold;\">\n<div style=\"font-family: 'Courier New', Courier, monospace; font-weight: normal;\">Console.<span style=\"color: #0000FF;\">WriteLine<\/span><span style=\"color: #000000;\">&#40;<\/span>funcDel<span style=\"color: #000000;\">&#40;<\/span><span style=\"color: #FF0000;\">5<\/span><span style=\"color: #000000;\">&#41;<\/span><span style=\"color: #000000;\">&#41;<\/span>;<\/div>\n<\/li>\n<\/ol>\n<\/div>\n<\/div>\n<p>&#196;quivalent mit Lampda Operator:<\/p>\n<div class=\"synthi_code\" style=\"display:none;\" id =\"plain_synthi_6ab2aefaa4b48\">\n<div class=\"synthi_header\" style=\"font-weight:bold;\"> CSharp <span  class=\"synthi_button\"style=\"font-weight:lighter;font-size:smaller;\">[<a href=\"#\" onClick=\"javascript:document.getElementById('styled_synthi_6ab2aefaa4b48').style.display='block';document.getElementById('plain_synthi_6ab2aefaa4b48').style.display='none';return false\">Show Styled Code<\/a>]:<\/span><\/div>\n<pre style=\"width:100%;overflow:auto;\">Func lambda = x =&gt; x + x;\r\nConsole.WriteLine(lambda(5));<\/pre>\n<\/div>\n<div class=\"synthi_code\" style=\"display:block;\" id =\"styled_synthi_6ab2aefaa4b48\">\n<div class=\"synthi_header\" style=\"font-weight:bold;\"> CSharp <span  class=\"synthi_button\"style=\"font-weight:lighter;font-size:smaller;\">[<a href=\"#\" onClick=\"javascript:document.getElementById('plain_synthi_6ab2aefaa4b48').style.display='block';document.getElementById('styled_synthi_6ab2aefaa4b48').style.display='none';return false\">Show Plain Code<\/a>]:<\/span><\/div>\n<div class=\"csharp\" style=\"font-family: monospace;\">\n<ol>\n<li style=\"font-weight: bold;\">\n<div style=\"font-family: 'Courier New', Courier, monospace; font-weight: normal;\">Func lambda = x =&amp;gt; x + x;<\/div>\n<\/li>\n<li style=\"font-weight: bold;\">\n<div style=\"font-family: 'Courier New', Courier, monospace; font-weight: normal;\">Console.<span style=\"color: #0000FF;\">WriteLine<\/span><span style=\"color: #000000;\">&#40;<\/span>lambda<span style=\"color: #000000;\">&#40;<\/span><span style=\"color: #FF0000;\">5<\/span><span style=\"color: #000000;\">&#41;<\/span><span style=\"color: #000000;\">&#41;<\/span>;<\/div>\n<\/li>\n<\/ol>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Delegates gibt es schon in C#, aber mit dem Lambda Operator (=&gt;) geht das nun k&#252;rzer. Folgendes generisches Beispiel (bisher): CSharp [Show Styled Code]: delegate T Func(T t); Func funcDel = delegate(int x) { return x + x; } Console.WriteLine(funcDel(5)); CSharp [Show Plain Code]: delegate T Func&#40;T t&#41;; Func&nbsp; funcDel = delegate&#40;int x&#41; &#123; return [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[27,12,448],"tags":[],"_links":{"self":[{"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/posts\/113"}],"collection":[{"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/comments?post=113"}],"version-history":[{"count":2,"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/posts\/113\/revisions"}],"predecessor-version":[{"id":512,"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/posts\/113\/revisions\/512"}],"wp:attachment":[{"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/media?parent=113"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/categories?post=113"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/tags?post=113"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}