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);
}
}
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: #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