Type detection: Difference between revisions
Content added Content deleted
Line 162: | Line 162: | ||
struct S |
struct S |
||
std::nullptr_t</pre> |
std::nullptr_t</pre> |
||
=={{header|C#|C sharp}}== |
|||
<lang csharp>using System; |
|||
namespace TypeDetection { |
|||
class C { } |
|||
struct S { } |
|||
enum E { |
|||
NONE, |
|||
} |
|||
class Program { |
|||
static void ShowType<T>(T t) { |
|||
Console.WriteLine("The type of '{0}' is {1}", t, t.GetType()); |
|||
} |
|||
static void Main() { |
|||
ShowType(5); |
|||
ShowType(7.5); |
|||
ShowType('d'); |
|||
ShowType(true); |
|||
ShowType("Rosetta"); |
|||
ShowType(new C()); |
|||
ShowType(new S()); |
|||
ShowType(E.NONE); |
|||
ShowType(new int[] { 1, 2, 3 }); |
|||
} |
|||
} |
|||
}</lang> |
|||
{{out}} |
|||
<pre>The type of '5' is System.Int32 |
|||
The type of '7.5' is System.Double |
|||
The type of 'd' is System.Char |
|||
The type of 'True' is System.Boolean |
|||
The type of 'Rosetta' is System.String |
|||
The type of 'TypeDetection.C' is TypeDetection.C |
|||
The type of 'TypeDetection.S' is TypeDetection.S |
|||
The type of 'NONE' is TypeDetection.E |
|||
The type of 'System.Int32[]' is System.Int32[]</pre> |
|||
=={{header|Crystal}}== |
=={{header|Crystal}}== |