Comments (5)
The following code is now legal in query clauses.
var strings = new string[1];
var r = from s in strings
select int.TryParse(s, out var i);
from csharplang.
Handing off to @AlekseyTs to drive the LDM discussion.
from csharplang.
I'm struggling to find documentation about exactly what this change entails, as the links seems to go around in a circle and end up on this page that seems to tell me that nothing has been implemented, yet it is listed in the Visual Studio 15.3 release notes as released.
Can anyone shed some light on this, or is it perhaps obvious to everyone but me what this change is about?
from csharplang.
See dotnet/roslyn#16270.
With C# 7.3 in VS2017 v15.7 (thought not the .NET Core CLI tools or Visual Studio for Mac yet), the following code is now legal. Previously, they would trigger the compiler error CS8200.
using System.Collections.Generic;
using System.Linq;
public class A
{
public A(int i)
{
}
public static int Magic = int.TryParse("123", out var i) ? i : 0;
}
public class B : A
{
public B(string s)
: base(int.TryParse(s, out var i) ? i : 0)
{
}
}
This covers both constzuctor-initializers and field-initialisers. I'm not sure about query clauses, I haven't been able to find an example that used to cause a compiler error but now works.
FWIW, the 2.7.0 compilers in SharpLab don't like the above just yet, but the master branch does.
from csharplang.
It seems that returns IEnumerable<bool>
.
Will this work too? I.e., referring to the expression's variable?
var r = from s in strings
select int.TryParse(s, out var i) ? i : (int?)null;
from csharplang.
Related Issues (20)
- [Proposal]: First-Class Span Types HOT 30
- [Proposal]: Collection Expressions Next (C#13 and beyond) HOT 47
- Open issues: Breaking changes HOT 29
- [Proposal]: Field and value as contextual keywords HOT 33
- [Proposal]: Extended identifier syntax
- [API Proposal]: IsNullableAttribute to flow nullability of generic type parameters into methods HOT 4
- Anonymous type optimization HOT 5
- Feature Request: Recursively Foreach
- [Proposal]: Relax `Add` requirement for collection expression conversions to types implementing `IEnumerable` HOT 2
- [Proposal]: Proposal for Allowing Single-Element Tuples in Type Definitions HOT 2
- [Proposal]: Params collections and older language versions HOT 1
- [Proposal]: Edit speclets to distinguish features already delivered from potential future enhancements HOT 3
- [Proposal]: `readonly` parameters in primary constructors for non-record types HOT 7
- [Issue]: Generic Type Specialization Not Working in C# HOT 38
- [Proposal]: AAAAAAAAAAAAAAAAAAAA
- Open questions for `field` and `value` as contextual keywords HOT 2
- Add collection literal support for `Memory<T>` and `ReadOnlyMemory<T>`. HOT 18
- Unexpected compiler behavior with records and implicit operators HOT 1
- YaoJunFeng
- Invalid implicit conversion from long to int HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from csharplang.