Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c#
uri
inequality
communitycreator

How to use the != operator to check if two URIs are equal in C#

Theodore Kelechukwu Onyejiaku

Overview

URI stands for Uniform Resource Identifier. It is used to represent a resource on the internet. This resource may be a code snippet, an image, an API, and so on.

We can check if two URIs in C# are unequal using the inequality operator.

Syntax

Uri1 != Uri2

Parameter values

Uri1 and Uri2: These are the URIs we want to check to see if they are unequal.

Return value

The value returned is a boolean. The value true is returned if they are not equal. Otherwise, the value false is returned.

Example

using System;
class HelloWorld
{
    static void Main()
    {
        // Create some Uri objects
        Uri uri1 = new Uri("https://www.educative.io/");
        Uri uri2 = new Uri("https://www.educative.io/");
        Uri uri3 = new Uri("https://www.educative.io/index.html");
        Uri uri4 = new Uri("https://www.educative.io/edpresso");

        // check if they are not equal
        Console.WriteLine(uri1 != uri2); // False
        Console.WriteLine(uri1 != uri3); // True
        Console.WriteLine(uri1 != uri4); // True
    }
}
Check if two URIs are unequal in C#

Explanation

  • Lines 7–10: We create some URI objects.
  • Lines 13–15: We check if some of the objects are not equal using the != operator, and then print the results to the console.

RELATED TAGS

c#
uri
inequality
communitycreator

CONTRIBUTOR

Theodore Kelechukwu Onyejiaku
RELATED COURSES

View all Courses

Keep Exploring