7

I hate the feature of c# that a member variable can be used as an function!

Let me get this variable. why does my cpu spike?
Because it calls 10 other functions to fill this float when needed.

float progress{
get { return DoWorkInDifferentFunctions(); }
}

Use this instead:

float CalculateProgress(){
return DoWorkInDifferentFunctions();
}

because people will use this like:

if(progress > 10.0f && progress < 25.0f){
DoStuff(progress);
}

Instead of:
float CurrentProgress = CalculateProgress();
if(CurrentProgress > 10.0f && CurrentProgress < 25%){
DoStuff(CurrentProgress );
}

@#$%&*$#^&*!!

Comments
  • 0
    Are working on sth like pentium1??
  • 2
    Thats.... Thats not a member variable, thats the exact same thing?
  • 1
    I don’t work with C#, but that’s looking worryingly similar the the mess of closures that are virtually mandatory in JavaScript programs...
  • 1
    @ganjaman *Properties
  • 3
    I actually love this feature. It makes accessors useless and your code much more readable. I never had a performance problem (although I don't use this feature on C#, but Vala). Now if you're trying to run this on a MIPS processor, good luck with that. After all, you're not using C# for performance, but for easier coding. Use C/C++ if you want performance
  • 3
    @Kaji It's useful. I find it better than accessors.
  • 2
    They are called properties and the first rule of properties is to not hide shit like that inside of them. It's seriously one of the best features.
  • 1
    @aggelalex Unfortunate a game engine such as unity3D uses C#. And who wants performance in games... You are right C/C++ would be better suited.
Add Comment