Uri.IsFile属性是Uri类的实例属性,用于检查指定的Uri是否是文件Uri。此属性返回一个布尔值。如果指定的Uri是文件Uri,则它返回true,否则返回false。此属性可能会生成System.InvalidOperationException异常。
语法:
public bool IsFile { get; }返回值:
此属性的返回类型为Boolean,如果Uri是文件URI ,则它返回一个布尔值,该值为true。否则为false。
演示Uri.IsFile属性示例的示例
using System;
class UriExample
{
//程序入口
static public void Main()
{
Uri domainUri;
Uri domainUri1;
domainUri = new Uri("https://www.nhooo.com:8082");
domainUri1 = new Uri("file://myServer/article.text");
if (domainUri.IsFile)
Console.WriteLine("Given Uri is a file Uri");
else
Console.WriteLine("Given Uri is not a file Uri");
if (domainUri1.IsFile)
Console.WriteLine("Given Uri is a file Uri");
else
Console.WriteLine("Given Uri is not a file Uri");
}
}输出结果
Given Uri is not a file Uri Given Uri is a file Uri
在上面的程序中,我们创建了一个Uri类的对象,该对象用带有端口号的网站名称初始化,在这里我们检查给定的Uri是文件Uri还是不使用Uri类的IsFile属性。