Interesting. And I need to give some thought because when calling Assert.AreEqual<T1, T2>(T1 object1, T2 object2) where T1 does not equal T2 will map to Assert.AreEqual(object, object) without compile time warning.
var str =String.Join(", ",SupportedNotificationMethods.Select(s => s.ToString()));
You can read more about the String.Join method at MSDN. Older versions of String.Join don’t have an overload that takes an IEnumerable. In that case just call ToArray() after select.
If you just care about existence, you could use ContainsValue(0) or Any(p => p.Value == 0) instead? Searching by value is unusual for a Dictionary<,>; if you were searching by key, you could use TryGetValue.
One other approach:
var record = data.Where(p => p.Value==1).Select(p =>new{Key= p.Key,Value= p.Value}).FirstOrDefault();
This returns a class – so will be null if not found.
The trick is this portion:
p =>new{Key= p.Key,Value= p.Value}
It introduces an anonymous type with two fields: Key and Value. (Note you can introduce any anonymous type here). Since these are classes, FirstOrDefault will return null if nothing was found.
Had to investigate some Assembly Loading issues, so I wrote two batch files to enable and disable the .NET Fusion Log:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
For a long time, I’ve persuading people to install English versions of their operating systems (especially on server side) at least for some parts of their environment.
The main reason is that searching for English error messages gives you a much bigger chance of finding the cause than non-English ones.
I’m still standing by that recommendation, but life has become a bit easier because of these two sites that offer quite good translations of Windows Error messages in many languages to English:
It is all about handling values that are not Integers, Overflow values and Nulls. There are subtle differences, in the handling of the methods, and the exceptions they could throw: ArgumentNullException, FormatException and OverflowException.
During a recent code review, I bumped into a couple of C# constructors having boolean parameters, leading to the dreaded magic booleans code smell.
This reminded me of the infamous Avoiding Booleans post on Coding Horror, which now is almost 10 years old.
To celebrate, I will coin the Dutch phrase when marking these in a review:
Boolean parameters en literals zijn vrijwel altijd een zwaktebod. Een teken dat beter nagedacht moet worden over het doel van de code.
The Dutch word zwaktebod is used when bidding Bridge using the Acol system. It is the equivalent of a “weak takeout” response to a bid of 1 NT (notrump or no trump, in other languages sometimes sans atout).
The English translation is just about this:
Boolean parameters and literals virtually always are a sign of weakness. It indicates you need to give more thought to the goal of the code.
In a funny way, he explains why the simplest fundamentals of computer software text, dates and numbers can cause some real headache for the programmer…