C#教程
C#控制语句
C#函数
C#数组
C#面向对象
C#命名空间和异常
C#文件IO
C#集合
C#多线程
C#其它

C# String IsInterned()

C# String IsInterned()

C# IsInterned() 方法用于获取指定字符串的引用。
Intern() 和 Intern() 的区别IsInterned() 是 Intern() 方法在字符串未被实习时实习,但 IsInterned() 不这样做。在这种情况下,IsInterned() 方法返回 null。
签名
public static string IsInterned(String str)

参数

str: 是字符串类型参数。
返回
它返回一个引用。

C# String 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# String 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
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4