language-specifications

Where can I find the C# 5 language specification?

纵然是瞬间 提交于 2019-12-17 17:48:06
问题 C# 5.0 is out now since August 2012. Where can I find the specification? They've stopped doing ECMA specs, but how about MSDN? 回答1: It was originally unavailable online but since June 2013 it is available for download from Microsoft. 回答2: If you have Visual Studio 2012 installed, you will find specification somewhere there: c:\Program Files (x86)\Microsoft Visual Studio 11.0\VC#\Specifications\1033\CSharp Language Specification.docx similar with VS2013: c:\Program Files (x86)\Microsoft Visual

Where Can I Find the C# Language Specification 6.0? [closed]

强颜欢笑 提交于 2019-12-17 17:33:54
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . I know where to find the C# 5 Language Specification but I cannot find the C# 6 Language Specification anywhere. Where is the C# 6 Language Specification? 回答1: At time of writing (May 2016) Microsoft hasn't yet finished updating the spec for C#6. In the meantime, I put up Microsoft's latest current draft of the

Why does C# not allow generic properties?

拈花ヽ惹草 提交于 2019-12-17 10:59:11
问题 I was wondering why I can not have generic property in non-generic class the way I can have generic methods. I.e.: public interface TestClass { IEnumerable<T> GetAllBy<T>(); //this works IEnumerable<T> All<T> { get; } //this does not work } I read @Jon Skeet's answer, but it's just a statement, which most probably is somewhere in the specifications. My question is why actually it is that way? Was kind of problems were avoided with this limitation? 回答1: Technically, the CLR supports only

When can a generic parameter never be null

心已入冬 提交于 2019-12-12 11:21:49
问题 In a generic GetHashCode(T foo) method, I check whether foo is null . However I just stumbled upon a strange Resharper warning. In the following code, can foo never be null ? private class FooComparer<T> : IEqualityComparer<T> where T: Foo { public int GetHashCode(T foo) { // resharper warning: "Expression is always false" if (Object.ReferenceEquals(null,foo)) return 0; // ... calculate hash } } However as far as I can tell, the following is perfectly legal: Foo foo = null; var fooComparer =

Has the C# spec (team? committee?) ever considered this object creation syntax?

随声附和 提交于 2019-12-12 10:31:35
问题 I've never posted a question of this nature before, so if it's not proper for SO, just don't hurt my feelings too bad and I'll delete it. In the interest of keeping everything I care about as close to the left margin as possible, I keep wishing I could write something like: DataService1.DataEntities dataEntities = new(constructorArg1, ...) I think another reason is I like the extra screen real estate I get by using var when the type is already present on the right side of the assignment, but

++i operator difference in C# and C++

这一生的挚爱 提交于 2019-12-10 12:43:05
问题 I have the following code written in both C++ and C# int i=0; ++i = 11; After this C# compiler brings an error The left-hand side of an assignment must be a variable, property or indexer But C++ compiler generate this code with no error and I got a result 11 for value of i . What's the reason of this difference? 回答1: The difference is that pre-increment operator is lvalue in C++, and isn't in C#. In C++ ++i returns a reference to the incremented variable. In C# ++i returns the incremented

Why doesn't an array access expression of a null array reference throw a NullPointerException?

自闭症网瘾萝莉.ら 提交于 2019-12-05 10:14:05
Consider the following code: int[] r = null; r[0] = 1 % 0; I would have expected this to throw a NullPointerException : according to JLS Sec 15.7.1 : The left-hand operand of a binary operator appears to be fully evaluated before any part of the right-hand operand is evaluated. = is a binary operator (shown in JLS Sec 15.2 - JLS Sec 15.26 describes assignment operators), and fully-evaluating the left-hand operand will result in a NullPointerException . However, an ArithmeticException is thrown, indicating that the right-hand operand is evaluated before the left-hand operand is fully evaluated.

How to refer to a class when both simple and fully-qualified names clash

☆樱花仙子☆ 提交于 2019-12-04 02:22:29
Consider the following pathological example: class Ideone { static class ArrayList<T> { ArrayList() { System.out.println("!!"); } } static class java { static class util { static class ArrayList<T> { ArrayList() { System.out.println("Here"); } } } } public static void main(String[] args) { new ArrayList<>(); new java.util.ArrayList<>(); // Can I refer to the "usual" java.util.ArrayList? } } The two instances created in the constructor are of the nested classes. But how might I refer to the java.util.ArrayList that we all know and love in the same class? We can't import it, and we can't use the

runtime type vs compile-time type method invocation

淺唱寂寞╮ 提交于 2019-12-04 00:57:26
问题 The C# 4.0 specs read: When a virtual method is invoked, the runtime type of the instance for which that invocation takes place determines the actual method implementation to invoke. In a nonvirtual method invocation, the compile-time type of the instance is the determining factor. At first, I thought this had something to do with initialization. For example, given two initializations: BaseClass bcDerived = new Derived(); vs BaseClass bcBase = new BaseClass(); and an overload in a helper

Why is it not allowed in Java to overload Foo(Object…) with Foo(Object[])?

倖福魔咒の 提交于 2019-12-04 00:20:34
问题 I was wondering why it is not allowed in Java to overload Foo(Object[] args) with Foo(Object... args) , though they are used in a different way? Foo(Object[] args){} is used like: Foo(new Object[]{new Object(), new Object()}); while the other form: Foo(Object... args){} is used like: Foo(new Object(), new Object()); Is there any reason behind this? 回答1: This 15.12.2.5 Choosing the Most Specific Method talk about this, but its quite complex. e.g. Choosing between Foo(Number... ints) and Foo