yazabilirsiniz:C# 's uzantısı yöntemleri Scala eşdeğeri? C# '
using System.Numerics;
namespace ExtensionTest {
public static class MyExtensions {
public static BigInteger Square(this BigInteger n) {
return n * n;
}
static void Main(string[] args) {
BigInteger two = new BigInteger(2);
System.Console.WriteLine("The square of 2 is " + two.Square());
}
}}
Nasıl olur Scala gibi bu basit extension method görünüyor?
Uyarı "kare" nin herhangi bir çağrısı, yansıtma (bir performans katili) kullanılarak yapılacaktır. 'Square'i tanımlayan ve' richInt 'yönteminden döndürülen bir "RichInt" sınıfı tanımlamak daha iyi olurdu. –
@Daniel, açıkladığınız kodu gönderebilir misiniz? – OscarRyz
@Support RichInt (i: Int) sınıfını ekle {def square = i * i} 'MyExtensions 've' richInt' yönteminde 'new RichInt (i)' yap. –