當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


C# Uri.Fragment用法及代碼示例

Uri.Fragment 屬性是實例屬性,用於獲取轉義的 URI 片段。

用法:

public string Fragment { get; }

返回值:此屬性返回包含任何 URI 片段信息的字符串。

異常:此屬性為相對 URI 拋出 InvalidOperationException 並且僅對絕對 URI 有效。

範例1:



C#


// C# program to demonstrate the  
// Uri.Fragment property  
using System;  
using System.Globalization;  
      
class GFG {  
      
     // Main Method  
    public static void Main()  
    {  
        // Declaring and initializing value1  
        Uri  v1 = new Uri("https://www.geeksforgeeks.org/greedy-algorithms/#standardGreedyAlgorithms");
          
       // using Fragment property  
        Console.WriteLine("Uri Fragment:"+ v1.Fragment);  
    }  
}

輸出:

Uri Fragment:#standardGreedyAlgorithms

範例2:

C#


// C# program to demonstrate the  
// Uri.Fragment property  
using System;  
using System.Globalization;  
      
class GFG {  
      
     // Main Method  
    public static void Main()  
    {  
        // Declaring and initializing value1  
        Uri  v1 = new Uri("https://www.geeksforgeeks.org/greedy-algorithms/#approximateGreedyAlgorthms");
         
        // using Fragment property  
        Console.WriteLine("Uri Fragment:"+ v1.Fragment);  
    }  
}

輸出:

Uri Fragment:#approximateGreedyAlgorthms



相關用法


注:本文由純淨天空篩選整理自shivanisinghss2110大神的英文原創作品 Uri.Fragment Property in C# with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。