PageRenderTime 53ms CodeModel.GetById 50ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/Test/keyword_implicit.cs

http://github.com/fishman/ctags
C# | 30 lines | 23 code | 4 blank | 3 comment | 2 complexity | 55abd1981d0785994063e141a2b98344 MD5 | raw file
Possible License(s): GPL-2.0
 1// cs_keyword_implicit.cs
 2using System;
 3struct Digit
 4{
 5   byte value;
 6
 7   public Digit(byte value) 
 8   {
 9      if (value < 0 || value > 9) throw new ArgumentException();
10      this.value = value;
11   }
12
13   // define implicit Digit-to-byte conversion operator:
14   public static implicit operator byte(Digit d) 
15   {
16      Console.WriteLine( "conversion occurred" );
17      return d.value;
18   }
19}
20
21class Test 
22{
23   public static void Main() 
24   {
25      Digit d = new Digit(3);
26
27      // implicit (no cast) conversion from Digit to byte
28      byte b = d;   
29   }
30}