📜  C#中的Uri.GetLeftPart()方法与示例

📅  最后修改于: 2021-05-30 01:13:43             🧑  作者: Mango

Uri.GetLeftPart()方法是一个实例方法,用于基于传递的UriPartial枚举从给定URI中获取指定部分。

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

范例1:

C#
// C# program to demonstrate the 
// Uri.GetLeftPart() Method 
using System; 
using System.Globalization; 
    
class GFG { 
    
     // Main Method 
    public static void Main() 
    { 
        // Declaring and initializing Uri 
        Uri  val;
          
        val = new Uri("https://www.geeksforgeeks.org/data-structure");
          
        // Use of Uri.GetLeftPart() Method
        // Getting the Authority
        string str = val.GetLeftPart(UriPartial.Authority);
          
        Console.WriteLine(str); 
    } 
}


C#
// C# program to demonstrate the 
// Uri.GetLeftPart() Method 
using System; 
using System.Globalization; 
    
class GFG { 
    
     // Main Method 
    public static void Main() 
    { 
        // Declaring and initializing Uri 
        Uri  val;
          
        val = new Uri("https://www.geeksforgeeks.org/");
          
        // Use of Uri.GetLeftPart() Method
        // Getting the Path
        string str1 = val.GetLeftPart(UriPartial.Path);
        Console.WriteLine(str1); 
          
        // Getting the Query
        string str2 = val.GetLeftPart(UriPartial.Query);
        Console.WriteLine(str2);
          
        // Getting the Scheme
        string str3 = val.GetLeftPart(UriPartial.Scheme);
        Console.WriteLine(str3);
    } 
}


输出:

https://www.geeksforgeeks.org

范例2:

C#

// C# program to demonstrate the 
// Uri.GetLeftPart() Method 
using System; 
using System.Globalization; 
    
class GFG { 
    
     // Main Method 
    public static void Main() 
    { 
        // Declaring and initializing Uri 
        Uri  val;
          
        val = new Uri("https://www.geeksforgeeks.org/");
          
        // Use of Uri.GetLeftPart() Method
        // Getting the Path
        string str1 = val.GetLeftPart(UriPartial.Path);
        Console.WriteLine(str1); 
          
        // Getting the Query
        string str2 = val.GetLeftPart(UriPartial.Query);
        Console.WriteLine(str2);
          
        // Getting the Scheme
        string str3 = val.GetLeftPart(UriPartial.Scheme);
        Console.WriteLine(str3);
    } 
}

输出:

https://www.geeksforgeeks.org/
https://www.geeksforgeeks.org/
https://