Micro-optimization, or worrying about performance during development can be a waste of time. Most likely the improvement you make won’t be in the critical path, will be negligible, or worst of all increase the complexity and readability of your code for a minimal advantage.
Is there any impact in execution performance because of using
array.Length directly as
for exit condition? Which one of following methods will excute faster?
Dmitry Yudakov concludes through digging into the IL code generated by JIT compiler for both methods:
… both methods will compile into the exact same code, but the first one is written faster, even though there isn’t any benefit in terms of execution time.
Michael Shpilt, in this article, provides eight techniques to minimize GC pressure and improve the performance of your .NET application. GC Pressure is when the GC doesn’t keep up with memory deallocations and application spend more time on garbage collection and less executing actual code.
Spoiler: Answer is NO!
Current implementation C# Enum is very primitive; it can only return integer value for the selected enumerator option. If your project requirement needs something like returning a string for Enum, you have to come up with your own solution.
You cannot declare
enum like this:
One solution usually popular is to declare
Description attribute to each enumerators (for example,
[Description("WT003")] for Contractor) and use it to store a respective string value. This is more of a hack work to as intend of
Description attribute is to provide description for enumerators for documentation purpose only. With that, you then also require to use reflection to pull the string from
Description attribute. This is not a clean solution.
I think the best way to implement the solution is through creating a dedicated class instead and provide all implementation underneath to make it behave like an
We set the Constructor of the class as
private which will keeping this class initiated anywhere in the project. All this class is exposing is defined members and
Value property in which are interested in.
We can then further extend this class by overriding
Equals and implementing
!= operators. Complete implementation will look like this:
Once we establish the pattern using the above implementation, it’s just a matter of replicating this pattern for other complex enums which has this string return value requirements. I hope this help!
Unfortunately there is no method to call DataTable.Add with the column size. This extension method will fix that:
Yes, you can now compile your C# or VB.NET code online, simply put your code in the provided text box and click “Compile Now” button. Compilr will compile your code and will provide you a link as well to download the compiled version of your code. Any error while compilation will display an error message on the page.