3 ms·
using System; public class Program { public class Person { private string _name; private int _age; public Person(string name, int
by jakevn 12y ago
using 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.