In this installment of my ongoing series covering likely C# 6 language features I’ll be covering one of the features listed as “Done” on the Language feature implementation status page: using static. The idea behind using static is to allow importing members from static classes thus removing the requirement to qualify every member of an imported class with its owner. For the F#ers reading this, using static brings open module to C#.
Consider a method that writes some text to the console:
In this example, we’ve had to specify the Console class three times. The using static feature we can simply invoke the WriteLine method:
The primary benefit in this contrived example is eliminating redundancy but consider a more practical example which makes use of some of System.Math’s members:
Here we’ve had to qualify both PI and Pow with the Math class. Granted, it only appears twice when calculating the area…
View original post 86 more words
Leave a Reply