How to use Uri.TryCreate() to check valid URI in C#

2 Answers

0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            Uri uri;
            if (Uri.TryCreate("http://www.collectivesolver.com/", UriKind.Absolute, out uri))
                Console.WriteLine(uri); 
        }
    }
}


/*
run:
 
http://www.collectivesolver.com/

*/

 



answered Mar 11, 2017 by avibootz
0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            Uri uri;
            if (Uri.TryCreate("http://www.collectivesolver!com/", UriKind.Absolute, out uri))
                Console.WriteLine(uri); 
            else
                Console.WriteLine("Uri Error");
        }
    }
}


/*
run:
 
Uri Error

*/

 



answered Mar 11, 2017 by avibootz

Related questions

2 answers 279 views
3 answers 216 views
216 views asked Mar 11, 2017 by avibootz
1 answer 275 views
1 answer 243 views
1 answer 115 views
...