C# C# Basics Perform if / else

Danny Yang
Danny Yang
663 Points

receiving error CS1644

I am receiving the following error when trying to compile the code:

error CS1644: Feature `declaration expression' cannot be used because it is not part of the C# 6.0 language specification

Kevin Gates
Kevin Gates
12,872 Points

Please take a snapshot of your workspace and share it here. Here's how to do that: https://teamtreehouse.com/community/workspace-snapshots

Danny Yang
Danny Yang
663 Points

Thanks folks. Here is my workspace snapshot: https://w.trhou.se/pn71sawjii

In the console, I attempted to run these commands: mcs Program.cs && mono Program.exe

1 Answer

Steven Parker
Steven Parker
159,145 Points

That's an interesting error message. It indicates that the compiler correctly identified what you were trying to do (a declaration expression), but didn't perform it because it is a version 6 compiler. I believe that feature was originally planned for version 6 but wasn't introduced into the language until version 7.3.

So for now, keep this C#6.0 compiler happy by declaring your variable before the expression it is used in:

        int minutes;
        int.TryParse(entry, out minutes);

You could also change "TryParse" into a plain "Parse" since you are not using the return value:

        int minutes = int.Parse(entry);