Unexpected symbol `=>' in class, struct, or interface member declaration
I've came across a script written by a different author. I tried to implement it to my scene but received this error:
"Unexpected symbol `=>' in class, struct, or interface member declaration"
I've tried to look into lambda syntax but still confused on how it works and how to get rid of this error message. Here's the snippets
public IEnumerable<object> Description => ((IEnumerable<object>) this.description);
public IEnumerable<CSGPolygon> Polygons => this.root.AllPolygons;
public BSP Clone() => new BSP(this.root.Clone(), this.Bounds, this.description, this._createDescription);
What am I missing?
Answer by tanoshimi · Apr 18, 2016 at 07:21 PM
Personally not a fan of lambdas, but I think your syntax is missing the declaration of the argument types. Seeing as you don't appear to be passing any arguments, however, this would just be empty parentheses (like those that follow the signature of a regular method signature - void Start()
, etc.):
public IEnumerable<object> Description = () => ((IEnumerable<object>) this.description);
public IEnumerable<CSGPolygon> Polygons = () => this.root.AllPolygons;
public BSP Clone() = () => new BSP(this.root.Clone(), this.Bounds, this.description, this._createDescription);
I might be completely wrong though!
I received this error:
Unexpected symbol `=' in class, struct, or interface member declaration
Is there a way to rewrite to not use lambdas?
Oh yes, absolutely. Lambdas don't provide any additional functionality - they are "syntactic sugar" - which some people think makes code more concise, and therefore improves it. Personally, I find them awkward to read and avoid them, hence why I'm clutching at straws solving your problem.
What line number is it that's throwing the error? I've just noticed that your third declaration has parentheses as if it were a method, which I'm certainly not familiar with - should it not be?:
public BSP Clone = () => new BSP(this.root.Clone(), this.Bounds, this.description, this._createDescription);
Thumbs up for that one. I've started going through and adjust the code until I reached this one that looks like a method declaration:
public static bool IsDegenerateSet(IEnumerable<CSGVertex> set) =>
((from a in set
group a by a.Position into a
select a.First<CSGVertex>()).Count<CSGVertex>() < 3);
It throws the same error. I wonder if its the same solution as above?