StringPool
Never
namespace Test { internal static class Program { private static void Main() { string s; // Is Interned and Is Interned Reference string @null = null; // Is Interned and Is NOT Interned Reference string empty = string.Copy(string.Empty); if ((object)empty == (object) string.Empty) throw new Exception(""); // Is Interned and Is Interned Reference string interned_InternedRef = "333"; // Is NOT Interned and Is NOT Interned Reference string notInterned_NotInternedRef = string.Concat(s = 9.ToString(), s, s); // Is Interned and Is NOT Interned Reference string interned_NotInternedRef = string.Concat(s = 3.ToString(), s, s); // It is impossible for a string to NOT be interned and is an interned reference // Therefore, an output of False, True is impossible. Out("@null", "True, True", @null); Out("empty", "True, False", empty); Out("interned_InternedRef", "True, True", interned_InternedRef); Out("notInterned_NotInternedRef", "False, False", notInterned_NotInternedRef); Out("interned_NotInternedRef", "True, False", interned_NotInternedRef); } private static string ToInfoString(string value) { if ((object)value == null) return "(-1)<null>"; if (value.Length == 0) return "(0)``"; return "(" + value.Length.ToString() + ")`" + value + "`"; } private static void Out(string header, string correctOutput, string value) { Console.WriteLine(header + "\r\nCorrect Output:" + correctOutput + "\r\nValue:" + ToInfoString(value)); Console.Write("--------------------\r\n"); string interned; bool isInterned = StringPool.TryGetInterned(value, out interned); Console.WriteLine("Is Interned:" + isInterned.ToString()); Console.WriteLine("Is Interned Reference:" + (isInterned && (object)value == (object)interned).ToString()); Console.Write("--------------------\r\n"); } } } namespace RedSkies { public static class StringPool { /// <summary> /// Retrieves the system's reference to the specified string if available; otherwise <paramref name="value" /> is returned. /// </summary> /// <returns>The system's reference to the specified string if available; otherwise <paramref name="value" />.</returns> public static string TryGetInterned(string value) { if ((object)value == null) return null; if (value.Length == 0) return string.Empty; string interned; return (object)(interned = string.IsInterned(value)) == null ? value : interned; } /// <summary> /// Replaces <paramref name="value" /> with the retrieved the system's reference to the specified string if available. /// </summary> public static void TryGetInterned(ref string value) { if ((object)value == null) { value = null; return; } if (value.Length == 0) { value = string.Empty; return; } string interned; if ((object)(interned = string.IsInterned(value)) == null) return; value = interned; } /// <summary> /// Retrieves the system's reference to the specified string if available. /// </summary> /// <returns><langword name="true" /> if the specified string is available in the system's string pool; otherwise <langword name="false" />.</returns> // TODO: Check IL to see if the labels create more bytes in the method. If so, then don't use the labels. public static bool TryGetInterned(string value, out string interned) { if ((object)value == null) { interned = null; goto RETURN_TRUE; } if (value.Length == 0) { interned = string.Empty; goto RETURN_TRUE; } if ((object)(interned = string.IsInterned(value)) == null) goto RETURN_FALSE; RETURN_TRUE: return true; RETURN_FALSE: interned = null; return false; } } }
Raw Text
-
etukteuketk
10 min ago
-
I lost my pussy at cards so that he would rip my tights and insert his dick
13 min ago
-
sdfgndasdfbn adsdfg
33 min ago
-
Untitled
35 min ago
-
UNDER AGE 11YR T
38 min ago
-
REAL PEDQFILI4 T
39 min ago
-
d2play best stream T
39 min ago
-
Look like now and T
40 min ago
-
Look like now and T https://exe.io/C2aeF
41 min ago
-
100 Latestnew Dōods T https://exe.io/xLTdcA
43 min ago