C# IsInterned() 方法用於獲取指定字符串的引用。
Intern() 和 IsInterned() 之間的區別在於,如果 Intern() 方法不實習,則 Intern() 方法實習字符串,但 IsInterned() 不實習。在這種情況下,IsInterned() 方法返回 null。
簽名
public static string IsInterned(String str)
參數
str:它是一個字符串類型參數。
返回
它返回一個引用。
C# 字符串 IsInterned() 方法示例
using System;
public class StringExample
{
public static void Main(string[] args)
{
string s1 = "Hello C#";
string s2 = string.Intern(s1);
string s3 = string.IsInterned(s1);
Console.WriteLine(s1);
Console.WriteLine(s2);
Console.WriteLine(s3);
}
}
輸出:
Hello C# Hello C# Hello C#
C# 字符串 Intern() 與 IsInterned() 示例
using System;
public class StringExample
{
public static void Main(string[] args)
{
string a = new string(new[] {'a'});
string b = new string(new[] {'b'});
string.Intern(a); // Interns it
Console.WriteLine(string.IsInterned(a) != null);//True
string.IsInterned(b); // Doesn't intern it
Console.WriteLine(string.IsInterned(b) != null);//False
}
}
輸出:
True False
相關用法
- C# String IsNormalized()用法及代碼示例
- C# String IsNullOrWhiteSpace()用法及代碼示例
- C# String IsNullOrEmpty()用法及代碼示例
- C# String IndexOf()用法及代碼示例
- C# String Insert()用法及代碼示例
- C# String ToLower()用法及代碼示例
- C# String ToString()用法及代碼示例
- C# String Contains()用法及代碼示例
- C# String ToCharArray()用法及代碼示例
- C# String TrimEnd()用法及代碼示例
- C# String Concat()用法及代碼示例
- C# String GetTypeCode()用法及代碼示例
- C# String Equals()用法及代碼示例
- C# String Split()用法及代碼示例
- C# String SubString()用法及代碼示例
- C# String Normalize()用法及代碼示例
- C# String Compare()用法及代碼示例
- C# String LastIndexOfAny()用法及代碼示例
- C# String EndsWith()用法及代碼示例
- C# String Trim()用法及代碼示例
注:本文由純淨天空篩選整理自 C# String IsInterned()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。