📜  C#| Uri.CheckSchemeName(String)方法

📅  最后修改于: 2021-05-29 23:51:45             🧑  作者: Mango

Uri.CheckSchemeName(String)方法用于确定指定的方案名称是否有效。

下面的程序说明了Uri.CheckSchemeName()方法的用法:

范例1:

// C# program to demonstrate the
// Uri.CheckSchemeName(string) Method
using System;
using System.Globalization;
  
class GFG {
  
    // Main Method
    public static void Main()
    {
        // Declaring and initializing Uri
        Uri uri = new Uri("http://www.geeksforgeeks.org");
  
        // Determining the Scheme of the Uri
        string scheme = uri.Scheme;
  
        // using CheckSchemeName() method
        bool value = Uri.CheckSchemeName(scheme);
  
        // Displaying the result
        if (value)
            Console.WriteLine("Scheme name is valid");
        else
            Console.WriteLine("Scheme name is invalid");
    }
}
输出:
Scheme name is valid

范例2:

// C# program to demonstrate the
// Uri.CheckSchemeName(string) Method
using System;
using System.Globalization;
  
class GFG {
  
    // Main Method
    public static void Main()
    {
        // Declaring and initializing Uri
        Uri uri = new Uri("https://www.pierobon.org/iis/review1.htm.html#one");
  
        // Determining the Scheme of the Uri
        string scheme = uri.Scheme;
  
        // using CheckSchemeName() method
        bool value = Uri.CheckSchemeName(scheme);
  
        // Displaying the result
        if (value)
            Console.WriteLine("Scheme name is valid");
        else
            Console.WriteLine("Scheme name is invalid");
    }
}
输出:
Scheme name is valid

参考:

  • https://docs.microsoft.com/zh-cn/dotnet/api/system.uri.checkschemename?view=netstandard-2.1