سؤال

I am using code:

Uri.TryCreate(sURL, UriKind.Absolute, out URI)

which works fine.

Do I need to call Uri.IsWellFormedUriString(sURL, UriKind.Absolute) ? I mean I want to know what is the use of Uri.IsWellFormedUriString when Uri.TryCreate works perfectly?

هل كانت مفيدة؟

المحلول

Uri.IsWellFormedUriString calls TryCreate internally as well as calling Uri.IsWellFormedOriginalString so the results may differ from simply calling TryCreate.

From ILSpy

public static bool IsWellFormedUriString(string uriString, UriKind uriKind)
{
    Uri uri;
    return Uri.TryCreate(uriString, uriKind, out uri) && uri.IsWellFormedOriginalString();
}

From MSDN

[Uri.IsWellFormedOriginalString] indicates whether the string used to construct this Uri was well-formed and is not required to be further escaped.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top