C# 属性

C# 抽象

C# 字符串

C# 泛型

C# 杂项

C# 新特性

C# IsInterned() 检索字符串

C# IsInterned() 方法用于获取指定字符串的引用。

Intern() 和 IsInterned() 之间的区别在于 Intern() 方法在字符串没有被实习的情况下实习,但 IsInterned() 不这样做。在这种情况下,IsInterned() 方法返回 null。

签名

句法 (Syntax)

public static string IsInterned(String str)

范围

str:字符串类型参数。

返回

它返回一个引用。


C# String IsInterned() 方法示例

例子 (Example)

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

输出:

你好C#
你好C#
你好C#

C# String Intern() 与 IsInterned() 示例

例子 (Example)

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


  • 使用社交账号登录,本站支持
全部评论(0)