Home » C#

C# | Uri.TryCreate() Method with Example

Uri.TryCreate() Method: Here, we are going to learn about the TryCreate() method of Uri class with example in C#.
Submitted by Nidhi, on March 26, 2020

Uri.TryCreate() Method

Uri.TryCreate() method is used to create a new Uri using specified enum UriKind. And here we get new Uri in the specified output parameter.

Syntax:

    bool Uri.TryCreate(string uriString, UriKind kind, out Uri outUri);

Parameter(s):

  • string uriString – represents the string to create new Uri.
  • UriKind kind – represents the UriKind enum to create new Uri.
  • out Uri outUri – represents the output variable to create new instance.

Return value:

The return type of this method is boolean, it returns true on successful creation of Uri, otherwise it returns false.

Example to demonstrate example of Uri.TryCreate() method

using System;

class UriExample
{
    //Entry point of Program
    static public void Main()
    {
        Uri createdUri = null;

        Uri.TryCreate("https://www.includehelp.com", UriKind.Absolute, out createdUri);

        System.Console.WriteLine("Created Uri: "+createdUri);
    }
}

Output

Created Uri: https://www.includehelp.com/
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.