A better way to validate URL in C# than try-catch?

前端 未结 10 1003
栀梦
栀梦 2020-12-13 12:08

I\'m building an application to retrieve an image from internet. Even though it works fine, it is slow (on wrong given URL) when using try-catch statements in the applicatio

10条回答
  •  旧时难觅i
    2020-12-13 12:30

    Use it.....

    string myString = http//:google.com;
    Uri myUri;
    Uri.TryCreate(myString, UriKind.RelativeOrAbsolute, out myUri);
     if (myUri.IsAbsoluteUri == false)
     {
      MessageBox.Show("Please Input Valid Feed Url");
     }
    

提交回复
热议问题