why using method Uri.TryCreate
I get BOOL TRUE if the URI is not in Uri.Schema??.
Here the Uri.Schema from MSDN: http://msdn.microsoft.com/en-us/library/system.uri.scheme.aspx
Try for example a string "mail:foo"
it return True and I do not understand why.
Any ide开发者_JAVA技巧as? Maybe a bug in MS framework or maybe a bug in my head :-)?
public static bool IsValidUriHttp(string uriString)
{
Uri test = null;
return Uri.TryCreate(uriString, UriKind.Absolute, out test);
}
Thanks
If you see the Documentation then it says that:
The Scheme property returns the scheme used to initialize the Uri instance. This property does not indicate that the scheme used to initialize the Uri instance was recognized.
So it just shows the scheme no matter if it was a known scheme or not.
Also the Uri.TryCreate()
tries to create a Uri with any kind of scheme that it feels may be okay.
Like i tried this and see what i got:
Uri t = null;
Uri.TryCreate("rwr:dsffs",UriKind.Absolute, out t).Dump();
t.Dump();
精彩评论