language-features

Why doesn't VB.NET 9 have Automatic Properties like C# 3?

爱⌒轻易说出口 提交于 2019-12-05 00:52:29
Would having a nice little feature that makes it quicker to write code like Automatic Properties fit very nicely with the mantra of VB.NET? Something like this would work perfect: Public Property FirstName() As String Get Set End Property UPDATE: VB.NET 10 (coming with Visual Studio 2010 and .NET 4.0) will have Automatic Properties. Here's a link that shows a little info about the feature: http://geekswithblogs.net/DarrenFieldhouse/archive/2008/12/01/new-features-in-vb.net-10-.net-4.0.aspx In VB.NET 10 Automatic Properties will be defines like this: Public Property CustomerID As Integer One

Why can't I do ??= in C#?

℡╲_俬逩灬. 提交于 2019-12-04 23:04:17
I often find myself doing: foo = foo ?? x; Why can't I do: foo ??= x; Edit : I know it's not part of the language... My question is "why not"? I find the necessity to repeat "foo" to be unpleasing and potentially error-prone. It looks just as ugly as: foo = foo + x; In general, the C# language design team is conservative about adding new syntax. They say that the value of an addition to the language must be weighed against the cost of increased complexity in the language. Peter Hallam was the C# Compiler development lead for a while, and also a member of the C# language design team. He wrote

Calling methods inside if() - C#

百般思念 提交于 2019-12-04 18:09:00
问题 I have a couple of methods that return a bool depending on their success, is there anything wrong with calling those methods inside of the IF() ? //&& makes sure that Method2() will only get called if Method1() returned true, use & to call both methods if(Method1() && Method2()) { // do stuff if both methods returned TRUE } Method2() doesn't need to fire if Method1() returns FALSE. Let me know there's any problem with the code above. thank you. EDIT: since there was nothing wrong with the

C1x: When will it land, what to expect?

淺唱寂寞╮ 提交于 2019-12-04 16:24:02
问题 C99 still isn't supported by many compilers, and much of the focus is now on C++, and its upcoming standard C++1x. I'm curious as to what C will "get" in its next standard, when it will get it, and how it will keep C competitive. C and C++ are known to feed on one another's improvements, will C be feeding on the C++1x standard? What can I look forward to in C's future? 回答1: The ISO/IEC 9899:2011 standard, aka C11, was published in December 2011. The latest draft is N1570; I'm not aware of any

Can I determine who is calling a function or instantiating a class in Java? [duplicate]

ε祈祈猫儿з 提交于 2019-12-04 14:53:00
This question already has answers here : Closed 9 years ago . Possible Duplicate: In Java, how do i find the caller of a method using stacktrace or reflection? I'm just curious. I was requesting that feature sometimes, but then I solved it with more code. (the calling class said its name while calling the method) private Class getCallingClass() { return new SecurityManager() { protected Class[] getClassContext(){return super.getClassContext();} }.getClassContext()[2]; } OR public class Foo { public static final void main(final String[] args) { test(); } private static void test() { Throwable e

Static methods added in interfaces in java 1.8 [closed]

南笙酒味 提交于 2019-12-04 14:52:17
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 5 years ago . As we know that in java 1.8 static methods are allowed in interfaces , I have seen some answers like static methods defined in interface from jdk 1 8 why did they need to do so but I am not satisfied. Furthermore I think it may cause problems like : public interface MyInterface{ public static void

Confused by Boxing. Casting -1 to Int64 throws InvalidCastException

[亡魂溺海] 提交于 2019-12-04 11:13:13
问题 Ok I must be overlooking something extremely simple but I am lost. Given this object val = -1; var foo = (Int32)(val); var bar = (Int64)(val); The cast to Int64 throws and InvalidCastException. I recognize this is related to some strangeness with boxing but I don't understand the reasoning. From what I understand val is boxed as Int32 on the first line. Then when I try to cast as something other than Int32 InvalidCastException is thrown. I suppose this means that I am trying to unbox val as

How is Nullable<T> different from a similar custom C# struct?

不打扰是莪最后的温柔 提交于 2019-12-04 09:54:07
In Nullable micro-optimizations, part one , Eric mentions that Nullable<T> has a strange boxing behaviour that could not be achieved by a similar user-defined type. What are the special features that the C# language grants to the predefined Nullable<T> type? Especially the ones that could not be made to work on a MyNullable type. Of course, Nullable<T> has special syntactic sugar T? , but my question is more about semantics. Eric Lippert What I was getting at is: there is no such thing as a boxed nullable . When you box an int , you get a reference to a boxed int . When you box an int? , you

What advantages does Scala have over Java for concurrent programming?

戏子无情 提交于 2019-12-04 09:08:40
问题 How can scala make writing multi-threaded programs easier than in java? What can scala do (that java can't) to facilitate taking advantage of multiple processors? 回答1: The rules for concurrency are 1 avoid it if you can 2 share nothing if you can 3 share immutable objects if you can 4 be very careful (and lucky) For rule 2 Scala helps by providing a nicely integrated message passing library out of the box in the form of the actors. For rule 3 Scala helps to make everything immutable by

How to deal with the immutability of returned structs?

拈花ヽ惹草 提交于 2019-12-04 08:37:35
问题 I'm writing a game that has a huge 2D array of "cells". A cell takes only 3 bytes. I also have a class called CellMap, which contains the 2D array as a private field, and provides access to it via a public indexer. Profiling showed that a performance problem is caused by garbage collection of too many Cell objects. So I decided to make Cell a struct (it was a class). But now code like this doesn't work: cellMap[x, y].Population++; I can think of many options, but I don't really like any of