Have You Ever Seen This Method? @zoran-horvat
Have You Ever Seen This Method?  @zoran-horvat
Uploaded May 2024 | Updated November 2026, 3 days ago
One tiny little feature passed under the radar in .NET 6
Suppose you are defining a range of numbers, such as a percentage.
Some code could put an unrestricted input value into the valid bounds.
Substitute zero in case of a negative input.
Substitute one hundred in case of an input too large.
Alternatively, combine the Min and Max methods from the Math class.
That is so 2020!
Starting with .NET 6, the Math class has a new static method that does all this.
It is called Clamp, and it comes with overloads for all numeric types.
Just give it the value and the inclusive lower and upper bound.
The result is either the input value, if it is within bounds, or one or the other bound if the input was outside.
Follow the link to the long video for more hidden gems like this one.

▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
👨 About Me 👨
Hi, I’m Zoran, I have more than 20 years of experience as a software developer, architect, team lead, and more. I have been programming in C# since its inception in the early 2000s. Since 2017 I have started publishing professional video courses at Pluralsight and Udemy and by this point, there are over 100 hours of the highest-quality videos you can watch on those platforms. On my YouTube channel, you can find shorter video forms focused on clarifying practical issues in coding, design, and architecture of .NET applications.❤️
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
⚡️COPYRIGHT NOTICE:
The Copyright Laws of the United States recognize a “fair use” of copyrighted content. Section 107 of the U.S. Copyright Act states: “Notwithstanding the provisions of sections 106 and 106A, the fair use of a copyrighted work, including such use by reproduction in copies or phono records or by any other means specified by that section, for purposes such as criticism, comment, news reporting, teaching (including multiple copies for classroom use), scholarship, or research, is not an infringement of copyright." This video and our youtube channel, in general, may contain certain copyrighted works that were not specifically authorized to be used by the copyright holder(s), but which we believe in good faith are protected by federal law and the Fair use doctrine for one or more of the reasons noted above.

#csharp #dotnet #objectorientedprogramming
Have You Ever Seen This Method?Let C# Tuples Become Your Best FriendsEF Core Is DDD (Here Is Why)Use params Like a Pro in C# 13This Is Why You Still Must Learn the Theory of AlgorithmsLearn an Algorithm in 60 Seconds! – CombinationsLLMs Will Keep Producing Bugs Forever10 Essential Constructors in C# Every Developer Should KnowNullable References Tips and TricksIs Structural Inspection Part of Your Unit Testing Strategy?Functional Types in the Latest C#3 Game-Changing Tips for Writing Simpler Code
Zoran on C# |

Have You Ever Seen This Method?

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER