Unity 5.5.2f1 to 5.6.1f1 - interpolated strings error?

Viewed 3908

I've just updated my Unity version from 5.5.2f1 to 5.6.1f1. Suddenly I get the error:

Feature `interpolated strings' cannot be used because it is not part of the C# 4.0 language specification

The code below worked well before updating.

public class SensorData
{
    public int Timestamp { get; set; }
    public float Humidity { get; set; }
    public float Temp { get; set; }
    public int Light { get; set; }
    public int Button { get; set; }

    public override string ToString()
    {
        return $"{Timestamp}, {Humidity}, {Temp}, {Light}, {Button}";
    }
}

I don't have a clue if its supposed to still work.

3 Answers

I have had success using

string.format("{0},{1},{2},{3}, {4}", Timestamp, Humidity, Temp, Light, Button);

In Unity 2017 it's now possible to use interpolated strings in Unity if you change the .NET version that Unity uses. Interpolated strings is a feature from C# 6 which is released in .NET 4.6.

To change to .NET 4.6 go to: Edit > Project Settings > Player, expand "Other settings" and change the "Scripting Runtime Version" to .NET 4.6

For more info look at: https://docs.unity3d.com/Manual/ScriptingRuntimeUpgrade.html

In Unity 2018, Unity should use .NET 4.x by default so you should have access to interpolated strings without having to change anything.

Related