/Test/keyword_implicit.cs
http://github.com/fishman/ctags · C# · 30 lines · 23 code · 4 blank · 3 comment · 2 complexity · 55abd1981d0785994063e141a2b98344 MD5 · raw file
- // cs_keyword_implicit.cs
- using System;
- struct Digit
- {
- byte value;
- public Digit(byte value)
- {
- if (value < 0 || value > 9) throw new ArgumentException();
- this.value = value;
- }
- // define implicit Digit-to-byte conversion operator:
- public static implicit operator byte(Digit d)
- {
- Console.WriteLine( "conversion occurred" );
- return d.value;
- }
- }
- class Test
- {
- public static void Main()
- {
- Digit d = new Digit(3);
- // implicit (no cast) conversion from Digit to byte
- byte b = d;
- }
- }