Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Performance Benchmarks</strong></p> <pre><code>Catch exception: 10,000 good: 63,668 ticks 10,000 bad: 6,435,609 ticks Regex Pre-Screen: 10,000 good: 637,633 ticks 10,000 bad: 717,894 ticks COM Interop CLSIDFromString 10,000 good: 126,120 ticks 10,000 bad: 23,134 ticks </code></pre> <p><strong>COM Intertop (Fastest) Answer:</strong></p> <pre><code>/// &lt;summary&gt; /// Attempts to convert a string to a guid. /// &lt;/summary&gt; /// &lt;param name="s"&gt;The string to try to convert&lt;/param&gt; /// &lt;param name="value"&gt;Upon return will contain the Guid&lt;/param&gt; /// &lt;returns&gt;Returns true if successful, otherwise false&lt;/returns&gt; public static Boolean TryStrToGuid(String s, out Guid value) { //ClsidFromString returns the empty guid for null strings if ((s == null) || (s == "")) { value = Guid.Empty; return false; } int hresult = PInvoke.ObjBase.CLSIDFromString(s, out value); if (hresult &gt;= 0) { return true; } else { value = Guid.Empty; return false; } } namespace PInvoke { class ObjBase { /// &lt;summary&gt; /// This function converts a string generated by the StringFromCLSID function back into the original class identifier. /// &lt;/summary&gt; /// &lt;param name="sz"&gt;String that represents the class identifier&lt;/param&gt; /// &lt;param name="clsid"&gt;On return will contain the class identifier&lt;/param&gt; /// &lt;returns&gt; /// Positive or zero if class identifier was obtained successfully /// Negative if the call failed /// &lt;/returns&gt; [DllImport("ole32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, PreserveSig = true)] public static extern int CLSIDFromString(string sz, out Guid clsid); } } </code></pre> <hr> <p>Bottom line: If you need to check if a string is a guid, and you care about performance, use COM Interop. </p> <p>If you need to convert a guid in String representation to a Guid, use</p> <pre><code>new Guid(someString); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload