1

I'm using visual studio 2013. I found a project in github, that project is using Visual Studio 2015. I'm trying to compile it but I get an error using vs2013

Invalid token ';' in class, struct, or interface member declaration

Here code's :

private readonly Log _log;
public Log Log => _log; // What => Operator is doing ? Pointer ?

Yes, What new features of => operator in C# [6.0]? and is there any way to use C# 6.0 in vs2013?

etrupja
  • 2,710
  • 6
  • 22
  • 37
moien
  • 999
  • 11
  • 26
  • http://stackoverflow.com/questions/27093908/how-to-enable-c-sharp-6-0-feature-in-visual-studio-2013 – matcheek Oct 27 '16 at 13:38
  • 4
    No, upgrade your VS version. – Mark Phillips Oct 27 '16 at 13:39
  • C# 6.0 was introduced with VS 2015. There is no way to use it in VS 2013. https://github.com/dotnet/roslyn/wiki/New-Language-Features-in-C%23-6#expression-bodies-on-property-like-function-members – c0d3b34n Oct 27 '16 at 13:40
  • 1
    Or replace it by `public Log Log { get; private set; }`. – Uwe Keim Oct 27 '16 at 13:42
  • c# 6 has been introduced with Visual Studio 2015 so you only can use the body expression in VS 15 or later version – Tinwor Oct 27 '16 at 13:56
  • I like how [two questions about that operator](http://stackoverflow.com/questions/40282424/what-does-operator-mean-in-a-property-in-c) are asked the same day. :) – Visual Vincent Oct 27 '16 at 14:09

3 Answers3

7

It is a shorter version to write a readonly property.

public Log Log => _log;

equals

public Log Log { get { return _log; } }

But I know of no way to use this feature in older versions.

dryman
  • 660
  • 6
  • 16
2

This is an expression-bodied property, a new syntax for computed properties introduced in C# 6, which lets you create computed properties in the same way as you would create a lambda expression. So:

public int TwoTimes(int number)
{
    return 2*number;
}

is equivalent to

public int TwoTimes(int number) => 2 * number;

Note: C# 6.0 was introduced with VS 2015. You can not use it with an earlier version.

Ref: What does "=>" operator mean in a property in C#?

Community
  • 1
  • 1
etrupja
  • 2,710
  • 6
  • 22
  • 37
1

The problem is Visual Studio 2013 doesnt support C# 6.0. Convert it in an older way, like in answer before

private readonly Log _log;
public Log Log 
{
    get { return _log; }
}
c0d3b34n
  • 534
  • 7
  • 14
Alex Pashkin
  • 301
  • 4
  • 15