Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

C#

Convert String value to enum

1
2
3
4
5
6
7
8
public enum FileTypes
    {
        Text,
        XML,
        XAML
    }

FileTypes ftypes = (FileTypes)Enum.Parse(typeof(FileTypes), "XAML", true);
https://snipt.net/embed/8595d84b347b499ac283d6d20363ea51/
https://snipt.net/raw/8595d84b347b499ac283d6d20363ea51/
8595d84b347b499ac283d6d20363ea51
csharp
C#
8
2016-12-08T04:18:15
True
False
False
/api/public/snipt/17026/
convert-string-value-to-enum
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a> <a href="#L-8">8</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="k">public</span> <span class="k">enum</span> <span class="n">FileTypes</span> </span><span id="L-2"><a name="L-2"></a> <span class="p">{</span> </span><span id="L-3"><a name="L-3"></a> <span class="n">Text</span><span class="p">,</span> </span><span id="L-4"><a name="L-4"></a> <span class="n">XML</span><span class="p">,</span> </span><span id="L-5"><a name="L-5"></a> <span class="n">XAML</span> </span><span id="L-6"><a name="L-6"></a> <span class="p">}</span> </span><span id="L-7"><a name="L-7"></a> </span><span id="L-8"><a name="L-8"></a><span class="n">FileTypes</span> <span class="n">ftypes</span> <span class="p">=</span> <span class="p">(</span><span class="n">FileTypes</span><span class="p">)</span><span class="n">Enum</span><span class="p">.</span><span class="n">Parse</span><span class="p">(</span><span class="k">typeof</span><span class="p">(</span><span class="n">FileTypes</span><span class="p">),</span> <span class="s">&quot;XAML&quot;</span><span class="p">,</span> <span class="k">true</span><span class="p">);</span> </span></pre></div> </td></tr></table>
c#, enum

C

Enum

1
2
3
  enum {A, B=2, C=1, D};
  printf("%d %d %d %d\n", A, B, C, D);
  // 0 2 1 2
https://snipt.net/embed/da45ec4be6574774008df9be683a4778/
https://snipt.net/raw/da45ec4be6574774008df9be683a4778/
da45ec4be6574774008df9be683a4778
c
C
3
2016-12-10T05:37:04
True
False
False
/api/public/snipt/7402/
enum
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a> <span class="k">enum</span> <span class="p">{</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">C</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">D</span><span class="p">};</span> </span><span id="L-2"><a name="L-2"></a> <span class="n">printf</span><span class="p">(</span><span class="s">&quot;%d %d %d %d</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">,</span> <span class="n">C</span><span class="p">,</span> <span class="n">D</span><span class="p">);</span> </span><span id="L-3"><a name="L-3"></a> <span class="c1">// 0 2 1 2</span> </span></pre></div> </td></tr></table>
c, enum

Java

Convert string to enum equivalent

1
2
3
4
5
6
7
8
enum Colors {
  BLUE,
  WHITE
}

// ..

Colors blue = Enum.valueOf(Colors.class, "BLUE");
https://snipt.net/embed/874a923a13e2a05915e4202150f2eb46/
https://snipt.net/raw/874a923a13e2a05915e4202150f2eb46/
874a923a13e2a05915e4202150f2eb46
java
Java
8
2016-12-08T04:19:38
True
False
False
/api/public/snipt/3648/
convert-string-to-enum-equivalent
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a> <a href="#L-8">8</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="kd">enum</span> <span class="n">Colors</span> <span class="o">{</span> </span><span id="L-2"><a name="L-2"></a> <span class="n">BLUE</span><span class="o">,</span> </span><span id="L-3"><a name="L-3"></a> <span class="n">WHITE</span> </span><span id="L-4"><a name="L-4"></a><span class="o">}</span> </span><span id="L-5"><a name="L-5"></a> </span><span id="L-6"><a name="L-6"></a><span class="c1">// ..</span> </span><span id="L-7"><a name="L-7"></a> </span><span id="L-8"><a name="L-8"></a><span class="n">Colors</span> <span class="n">blue</span> <span class="o">=</span> <span class="n">Enum</span><span class="o">.</span><span class="na">valueOf</span><span class="o">(</span><span class="n">Colors</span><span class="o">.</span><span class="na">class</span><span class="o">,</span> <span class="s">&quot;BLUE&quot;</span><span class="o">);</span> </span></pre></div> </td></tr></table>
conversion, enum, string
Copyrighted, illegal, or inappropriate content? Email [email protected].