4 ms·
Can you give me examples of implicits in C# ? I am unable to see a parallel.
by hokkos 12y ago
Can you give me examples of implicits in C# ? I am unable to see a parallel.
- jakevn 12y agousing System; public class Program { public class Person { private string _name; private int _age; public Person(string name, int age) { _name = name; _age = age; } public static implicit operator int(Person p) { return 42; } } public static void Main() { var person = new Person("Jim", 51); var number = 100; AdditionPrinter(person, number); // Prints 142 } public static void AdditionPrinter(int a, int b) { Console.WriteLine(a + b); } }
- seanmcdirmid 12y agoAlso consider extension methods, which serve some of the same purpose as implicits in Scala.