tryparse

Why does IPAddress.TryParse allow anything after a ']'

I'd like to use System.Net.IPAddress.TryParse to validate IPv6 addresses because I don't want to write my own reg exp :-) However, this seems to allow strings such as "(validIPv6)](anythingatallhere)" - for example, "1234::5678:abcd]whargarbl". Is there a reason for these being valid, or is this a fault? This is further complicated by...

Generic TryParse

I am trying to create a generic extension that uses 'TryParse' to check if a string is a given type: public static bool Is<T>(this string input) { T notUsed; return T.TryParse(input, out notUsed); } this won't compile as it cannot resolve symbol 'TryParse' As I understand, 'TryParse' is not part of any interface. Is this pos...

Using TryGetValue() in LINQ?

This code works, but is inefficient because it double-lookups the ignored dictionary. How can I use the dictionary TryGetValue() method in the LINQ statement to make it more efficient? IDictionary<int, DateTime> records = ... IDictionary<int, ISet<DateTime>> ignored = ... var result = from r in records where !ignored.Cont...

Enum.TryParse not supporting in vs2008 in c#

Enum.TryParse(,,out) not supporting in vs2008 in c#? why? I am trying to use but getting error that TryParse no defined. ...

Best (safest) way to convert from double to int

I'm curious as to the best way to convert a double to an int. Runtime safety is my primary concern here (it doesn't necessarily have to be the fastest method, but that would be my secondary concern). I've left a few options I can come up with below. Can anyone weigh in on which is best practice? Any better ways to accomplish this that...

Objective C try parse boolean

I would like to know how, in Objective-C, how to tell if a string represents a boolean value. The [string boolValue] method will not work, because when I try to parse a string like [@"ERROR" boolValue] it returns NO instead of throwing an exception. In C#, I could do something like: if (Boolean.TryParse(string, out bool)), but this is no...

Does Int32.TryParse(String, Int32) alter the int argument on failure?

Out of interest, is it safe to assume that if Int32.TryParse(String, Int32) fails, then the int argument will remain unchanged? For example, if I want my integer to have a default value, which would be wiser? int type; if (!int.TryParse(someString, out type)) type = 0; OR int type = 0; int.TryParse(someString, out type); ...