Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Interning of String in C#
Interning of string optimizes memory and performance.
Through this, you can put strings in the runtime's shared string pool.
Let us see an example −
Example
using System;
using System.Text;
public class Demo {
public static void Main() {
string str1 = new StringBuilder().Append("Car is a ").Append("Vehicle").ToString();
// Interned string
string str2 = string.Intern(str1);
Console.WriteLine("Interned String"+str2);
}
}
Output
Interned StringCar is a Vehicle
Here, we can see Interned string −
string str2 = string.Intern(str1);
Advertisements