当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


C# Uri.CheckSchemeName(String)用法及代码示例


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

用法: public static bool CheckSchemeName (string schemeName);
Here, it takes the scheme name to validate.

返回值:如果方案名称有效,则此方法返回布尔值true,否则返回false。


以下示例程序旨在说明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

参考:



相关用法


注:本文由纯净天空筛选整理自RohitPrasad3大神的英文原创作品 C# | Uri.CheckSchemeName(String) Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。