0 امتیاز

با سلام

آیا از out و ref که در متدها در سیشارپ استفاده میکینیم در جاوا هم میشه استفاده کرد؟ من الان هرچی نوشتم ایراد میگرفت .

 

static int pow(out int a)

 

بسته شده

1 پاسخ

+2 امتیاز
 
بهترین پاسخ

سلام 

چنین امکانی در جاوا نیست عین مطلب از سایت جاوا

http://www.javacamp.org/javavscsharp/outparam.html

Java doesn't have out parameters.
You can achieve C#'s functionality by wrapping a primitive 
to a class, or using an array to hold multiple returned values, 
and then call back that value via pass by reference.

class Test {
    static void divide(int a, int b, int result, int remainder) {
        result = a / b;
        remainder = a % b;
        System.out.println(a +"/"+ b + " = "+ result + 
               " r " + remainder);
    }
    public static void main(String[] args) {
        for (int i = 1; i < 10; i++)
            for (int j = 1; j < 10; j++) {
                int ans = 0, r = 0;
                divide(i, j, ans, r);
            }
    }
}

 

سوال جدید

2,337 سوال

2,871 پاسخ

3,725 دیدگاه

3,919 کاربر

دسته بندی ها

...