TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

What's New in C# 6.0 [video]

227 pointsby chtonover 10 years ago

27 comments

iaskwhyover 10 years ago
You can also view a summary of the video&#x2F;features as a presentation: <a href="https://view.officeapps.live.com/op/view.aspx?src=http%3a%2f%2ffiles.channel9.msdn.com%2fthumbnail%2f6fcbe7ba-1cf1-4332-a9e3-ad559fe907c1.pptx" rel="nofollow">https:&#x2F;&#x2F;view.officeapps.live.com&#x2F;op&#x2F;view.aspx?src=http%3a%2f...</a>
评论 #8609133 未加载
评论 #8611485 未加载
评论 #8608218 未加载
felixriesebergover 10 years ago
Interestingly, if you&#x27;d like to check out how some of these features were implemented, you totally can. Roslyn is open-source (<a href="http://roslyn.codeplex.com/" rel="nofollow">http:&#x2F;&#x2F;roslyn.codeplex.com&#x2F;</a>).<p>That being said, I hope that all the open-sourcing is going to make it available where I really want to use it - Unity, for instance. (Disclaimer: I&#x27;m an open source dev @ Microsoft)
评论 #8609055 未加载
Tloewaldover 10 years ago
Nothing not to love -- a whole bunch of syntax sugar that makes code cleaner without messing around with core concepts that breaks code conceptually. It&#x27;s also great to see how quickly good ideas permeate the language landscape today versus ten years ago (or maybe it&#x27;s just good ideas finally permeating the landscape all at once).
评论 #8610573 未加载
评论 #8610754 未加载
zobzuover 10 years ago
I&#x27;m going to take some hits for that but... with .NET being open source (never liked Mono..) and all..<p>I&#x27;m tempted to use C# in the future again. Using it on Windows has always been good - and now that it compiles to native code too and that the libs are open....
评论 #8609305 未加载
评论 #8608617 未加载
JamesBarneyover 10 years ago
Still hoping they add the !(non-nullable) operator.<p>I know its hard <a href="http://blog.coverity.com/2013/11/20/c-non-nullable-reference-types/#.VGY_5fnF-QA" rel="nofollow">http:&#x2F;&#x2F;blog.coverity.com&#x2F;2013&#x2F;11&#x2F;20&#x2F;c-non-nullable-reference...</a><p>But dang I would appreciate it. So much code is cluttered with null checks that increases the robustness of the code at the cost of correctness, readability, and poorly defined behavior.
评论 #8609899 未加载
评论 #8609324 未加载
wbondover 10 years ago
While all of the changes look nice in terms of writing less code, they are the kind of syntactic sugar I learned to hate in CoffeeScript. Mostly because the code was so much denser and harder to read. Especially when reading other people&#x27;s code.<p>As I write more and more code, the more I want simplicity and ease of understanding over typing a few less characters or having more elegant code.
评论 #8608826 未加载
评论 #8608752 未加载
评论 #8610860 未加载
评论 #8609439 未加载
评论 #8609327 未加载
评论 #8610013 未加载
评论 #8611587 未加载
评论 #8609566 未加载
评论 #8611701 未加载
评论 #8609077 未加载
DenisMover 10 years ago
Still no first-class tuple support? Argh! All want is:<p><pre><code> var first, last = parseName(fullName); </code></pre> Instead of:<p><pre><code> String last; var first = parseName(fullName, out last);</code></pre>
评论 #8612988 未加载
评论 #8612618 未加载
评论 #8612040 未加载
Grieverover 10 years ago
Seems like a small change but that nameof(argument) method for ArgumentXExceptions is incredibly handy.
评论 #8608516 未加载
评论 #8608636 未加载
评论 #8608778 未加载
pilifover 10 years ago
Being able to use await in catch and finally must have been incredibly hard to implement for them. Especially in the finally part.<p>I mean - I&#x27;m saying this as somebody who hasn&#x27;t done a lot of C# or .NET work in the last few years, but think about what you would have to do if you had to implement this in a safe and bug-free way.
评论 #8608732 未加载
hvsover 10 years ago
The null-conditional operators and string interpolation are really cool.<p>I don&#x27;t use C# anymore (job change, not out of dislike), but I was always really happy working in it. I&#x27;m still not a huge fan of Windows, but C# is a wonderful language.
评论 #8609003 未加载
IdleChrisover 10 years ago
What&#x27;s new in VB 14 (video): <a href="http://channel9.msdn.com/Events/Visual-Studio/Connect-event-2014/113" rel="nofollow">http:&#x2F;&#x2F;channel9.msdn.com&#x2F;Events&#x2F;Visual-Studio&#x2F;Connect-event-...</a>
评论 #8610278 未加载
moron4hireover 10 years ago
Using static classes as namespaces addresses something I was just complaining about a week ago. Let&#x27;s take it a step further! Just let us put bare functions in namespaces without the dance of the static class.
评论 #8608865 未加载
评论 #8609094 未加载
louthyover 10 years ago
I think they missed a trick if the goal was to reduce boilerplate; which I&#x27;m all for, I&#x27;m very much moving away from C# to F# for this reason (and a few others).<p>Why this:<p><pre><code> public int X { get; } public int Y { get; } = 5; </code></pre> And not this:<p><pre><code> public int X get; public int Y get = 5; </code></pre> The braces serve absolutely no purpose anymore, the semi-colon doesn&#x27;t serve as a separator between statements. So why leave them?
评论 #8612104 未加载
评论 #8610393 未加载
评论 #8610312 未加载
评论 #8611933 未加载
noblethrasherover 10 years ago
I&#x27;m a tiny bit disappointed with the inclusion of exception filters, but I suppose it is pragmatic feature.<p>I&#x27;m fond of a pattern where error codes can be implicitly converted to Exceptions[1].<p>It&#x27;s often argued that exceptions are for things that your program cannot handle and error codes are for things that it can. But, in my experience, whether or not a bad condition is an error or an exception depends upon the layer in which the code lives.<p>Also, a side benefit of this scheme is that most of the exceptions show up in the class browser, or can be explored through reflection.<p>[1]<a href="https://gist.github.com/noblethrasher/ba37ed6176ebeb679dd2" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;noblethrasher&#x2F;ba37ed6176ebeb679dd2</a> -- In my example, the error code is an integer, but it could be another class that holds more information about the operation.
评论 #8610364 未加载
architguptaover 10 years ago
These are very nice changes. Especially the ability to write a quick lambda for named functions (or functions which are needed often).<p>The elvis operator is useful to. Makes me think sticking to F# will cause fewer classes of bugs that can happen in C# (the onChanged example is quite interesting).
sagivoover 10 years ago
i love the new &quot;?.&quot; similar to coffeescript. definitely make our lives easier.
评论 #8608983 未加载
zarothover 10 years ago
So these lines are now equivalent:<p><pre><code> public override string ToString() { return String.Format(&quot;({0}, {1})&quot;, X, Y); } public override string ToString() =&gt; &quot;(\{X}, \{Y})&quot; </code></pre> Could it go even further? This isn&#x27;t paper after all, on screen why shouldn&#x27;t it look like;<p><pre><code> public override string ToString() =&gt; &quot;(X, Y)&quot; </code></pre> where the X and Y are either slight italics or underlined or colored to indicate they mean X and Y the variable not X and Y the letters. The IDE would let you just toggle the state between &#x27;variable&#x27; and &#x27;literal&#x27; with the keyboard.<p>We also get better array initializers:<p><pre><code> public JObject ToJson() { var r = new JObject(); r[&quot;x&quot;] = X; r[&quot;y&quot;] = Y; return r; } </code></pre> becomes:<p><pre><code> public JObject ToJson() =&gt; return new JObject() { [&quot;x&quot;] = X, [&quot;y&quot;] = Y }; </code></pre> That&#x27;s cool! Next comes the null-conditional operators:<p><pre><code> public static Point FromJson(JObject json) { if (json != null &amp;&amp; json[&quot;x&quot;] != null &amp;&amp; json[&quot;x&quot;].Type == JTokenType.Integer &amp;&amp; json[&quot;y&quot;] != null &amp;&amp; json[&quot;y&quot;].Type == JTokenType.Integer) { return new Point((int)json[&quot;x&quot;], (int)json[&quot;y&quot;]); } return null; } </code></pre> Becomes...<p><pre><code> public static Point FromJson(JObject json) { if (json?[&quot;x&quot;]?.Type == JTokenType.Integer &amp;&amp; json?[&quot;y&quot;]?.Type == JTokenType.Integer) { return new Point((int)json[&quot;x&quot;], (int)json[&quot;y&quot;]); } return null; } </code></pre> The check against JTokenType.Integer is just to avoid a casting exception. The null checks are just to avoid null exceptions. I wonder if the compiler could ever handle something like &#x27;this if you can, else null&#x27;, without actually having any exceptions getting throw and caught underneath:<p><pre><code> public static Point FromJson(JObject json) =&gt; return new Point((int)json[&quot;x&quot;], (int)json[&quot;y&quot;]) ?: null;</code></pre>
评论 #8611577 未加载
评论 #8611987 未加载
评论 #8611663 未加载
评论 #8611905 未加载
swalshover 10 years ago
It&#x27;s funny that of all those, i&#x27;m most excited about nameof
hokkosover 10 years ago
Because primary constructor was slashed to make a true record type, my new favorite feature is the nameof operator, it is very useful with IPropertyChanged, when you have to use the name of a property to raise a change, it was not type safe if you refactored the name of the property, a workaround used Expression capturing using RaisePropertyChange(p =&gt; p.MyProperty) which is very slow (or a CallerMemberName attribute in C# 5 but can be abused), nameof is more elegant.<p>I also love the ?. operator.
Someone1234over 10 years ago
They need to add these:<p><a href="https://github.com/MiniProfiler/dotnet/blob/master/StackExchange.Profiling/Helpers/ExtensionMethods.cs" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;MiniProfiler&#x2F;dotnet&#x2F;blob&#x2F;master&#x2F;StackExch...</a><p>They&#x27;re extremely useful and intuitive string helper methods. Truncate(), IsNullOrWhiteSpace(), etc are things I use daily. And while you can type string.IsNullOrWhiteSpace(string) that is annoying and counter-intuitive.
评论 #8609382 未加载
评论 #8609561 未加载
fekbergover 10 years ago
I did a talk a few months back going over the changes up until today, and what is coming in C# 6, this was before they decided to drop primary constructors.<p><a href="https://www.youtube.com/watch?v=BA3sL783_Co" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=BA3sL783_Co</a>
mkhalilover 10 years ago
It all looks really promising. Love it.<p>I&#x27;m a little worried about &quot;nameof&quot; in the hand of amateur programmers though. Efficiency aside (because it&#x27;s not efficient), code readability might take a hit.
评论 #8609269 未加载
评论 #8609192 未加载
评论 #8609111 未加载
评论 #8609039 未加载
cesarbsover 10 years ago
I love the new read-only auto properties. 90% of the objects I write are immutable and it&#x27;s a pain to declare all those private readonly backing fields just to return them in getters.
评论 #8608966 未加载
评论 #8610425 未加载
BinaryIdiotover 10 years ago
Lots of little things but they&#x27;re pretty handy. I wish I still wrote in C#; perhaps that day will come when they start distributing the .Net runtime on Linux &#x2F; Mac OS X.
评论 #8609106 未加载
FlyingLawnmowerover 10 years ago
await in catch and finally is going to be great! I&#x27;m an amateur c# programmer, but I hated having to set flags that get called later to do async methods with try&#x2F;catch.
samjltaylorover 10 years ago
Good to see immutability being given some attention. Elvis operators though, I think they make code shorter rather than easier to understand
hkonover 10 years ago
More fun for the juniors who have just come to terms with the ternary operator.
评论 #8610982 未加载