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
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.
AOP allows you to perform separate of concerns (SoC) in your application, especially in the area of cross-cutting concerns like for instance logging, authorization, monitoring, etc.
It took a while in Delphi to allow for AOP, but the TVirtualMethodInterceptor (that introduced in Delphi 2010) can be used to do AOP (only for Virtual Methods, which is still way better than having no AOP at all).
The code requires a lot of manual labor. so I was glad that DSharp (a great library by Stefan Glienke – one of the leading Spring4D contributors) contains a nice wrapper around TVirtualMethodInterceptor so you can use AOP in an attribute based fashion.
Nick Hodges recorded a good introductory video on AOP in Delphi with slides and demo code:
But that is nowhere on the default path, nor in the registry.
What happens during installation of Visual Studio and/or the Microsoft SDK, is that the vsvars32.bat file of Visual Studio is updated so it can add the location of many tools (including xsd.exe) to the PATH.
So the trick is to find the youngest Visual Studio first, then run the according vsvars32.bat, and then xsd.exe is on the path.
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