Git Product home page Git Product logo

Comments (5)

SpazeDev avatar SpazeDev commented on July 17, 2024 3

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.

gafter avatar gafter commented on July 17, 2024

Handing off to @AlekseyTs to drive the LDM discussion.

from csharplang.

lassevk avatar lassevk commented on July 17, 2024

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.

yaakov-h avatar yaakov-h commented on July 17, 2024

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.

acelent avatar acelent commented on July 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.