SHOW:
|
|
- or go back to the newest paste.
| 1 | using System; | |
| 2 | using System.Collections.Generic; | |
| 3 | using System.Linq; | |
| 4 | using System.Text; | |
| 5 | ||
| 6 | namespace UseDoubleAlias | |
| 7 | {
| |
| 8 | class Program | |
| 9 | {
| |
| 10 | static void Main(string[] args) | |
| 11 | {
| |
| 12 | object value = 23.5; | |
| 13 | ||
| 14 | // "is" operator checks if given value can be converted to | |
| 15 | // given type. | |
| 16 | // Converting from object to other type - unboxing. | |
| 17 | // Note: Unboxing is one of the supported operations of | |
| 18 | // "is" operator. | |
| 19 | // See here for more on "is": http://msdn.microsoft.com/en-us/library/scekt9xw%28v=vs.71%29.aspx | |
| 20 | if (value is Double) | |
| 21 | {
| |
| 22 | Console.WriteLine(value + " is Double."); | |
| 23 | } | |
| 24 | else | |
| 25 | {
| |
| 26 | Console.WriteLine(value + " is not Double."); | |
| 27 | } | |
| 28 | ||
| 29 | if (value is System.Double) | |
| 30 | {
| |
| 31 | Console.WriteLine(value + " is System.Double."); | |
| 32 | } | |
| 33 | else | |
| 34 | {
| |
| 35 | Console.WriteLine(value + " is not System.Double."); | |
| 36 | } | |
| 37 | } | |
| 38 | } | |
| 39 | ||
| 40 | //Note: System.Double is struct but this is not so important in this example. | |
| 41 | class Double | |
| 42 | {
| |
| 43 | // Empty class(type) having the same name as System.Double. | |
| 44 | } | |
| 45 | } |