نمایش نتایج 1 تا 6 از 6

نام تاپیک: overload سازی همراه با OUT

  1. #1
    کاربر دائمی آواتار the Dead
    تاریخ عضویت
    خرداد 1385
    محل زندگی
    iN Hell
    پست
    127

    Tick overload سازی همراه با OUT


    مشکل این برنامه در کجاست؟

  2. #2
    چون متد f1 در کلاس Overdsa بصورت Static تعریف نشده ، شما باید ابتدا یک Instance از کلاس Overdsa بسازید و بعد از طریق آن ، متد f1 را فراخوانی کنید.


    string neo="Reza";
    overdsa ov=new overdsa();
    ov.f1("ali",out neo);

  3. #3
    کاربر دائمی آواتار the Dead
    تاریخ عضویت
    خرداد 1385
    محل زندگی
    iN Hell
    پست
    127
    عکس های ضمیمه عکس های ضمیمه
    • نوع فایل: jpg 2.JPG‏ (27.1 کیلوبایت, 15 دیدار)

  4. #4
    برای ارسال مقدار نمی توانید از پارامتر از نوع out استفاده کنید، برای منظور شما باید برای ارسال 'رضا' از یک پارامتر از جنس val دیگری استفاده کنید و فقط نتیجه را با پارامتر از جنس out به بیرون از متد انتقال دهید.

  5. #5
    نقل قول نوشته شده توسط the Dead مشاهده تاپیک

    مشکل این برنامه در کجاست؟
    فقط کلمه کلیدی out رو به ref تغییر بدید مشکل حل میشه.
    دلیل : از کلمه کلیدی out جایی استفاده کنید که فقط خروجی دارید و جایی که هم ورودی و هم خروجی رو میخواین با داشتن تنها یک متغیر حل کنید از ref استفاده کنید. (یک نکته : زمانی که پارامتر پاس شده از نوع reference type باشه قید کردن کلمه کلیدی ref هم نیازی نیست و پارامتر شما خودبخود خاصیت ref رو خواهد داشت.)
    ...مرا به خانه ام ببر، اگرچه خانه؛ خانه نیست

  6. #6
    بنقل از : http://www.csharphelp.com/archives/archive225.html

    There are four different ways of passing parameters to a method in C#‎.The four different types of parameters are
    1. Value
    2. Out
    3. Ref
    4. Params

    1.Value parameters This is the default parameter type in C#‎.If the parameter does not have any modifier it is "value" parameter by default. When we use "value" parameters the actual value is passed to the function,which means changes made to the parameter is local to the function and is not passed back to the calling part.
    using System;
    class ParameterTest
    {
    static void Mymethod(int Param1)
    {
    Param1=100;
    }
    static void Main()
    {
    int Myvalue=5;
    MyMethod(Myvalue);
    Console.WriteLine(Myvalue);
    }
    }
    Output of the above program would be 5.Eventhough the value of the parameter Param1 is changed within MyMethod it is not passed back to the calling part since value parameters are input only.

    2.Out parameters "out" parameters are output only parameters meaning they can only passback a value from a function.We create a "out" parameter by preceding the parameter data type with the out modifier. When ever a "out" parameter is passed only an unassigned reference is passed to the function.
    using System;
    class ParameterTest
    {
    static void Mymethod(out int Param1)
    {
    Param1=100;
    }
    static void Main()
    {
    int Myvalue=5;
    MyMethod(Myvalue);
    Console.WriteLine(out Myvalue);
    }
    }
    Output of the above program would be 100 since the value of the "out" parameter is passed back to the calling part. Note The modifier "out" should precede the parameter being passed even in the calling part. "out" parameters cannot be used within the function before assigning a value to it. A value should be assigned to the "out" parameter before the method returns.

    3.Ref parameters "ref" parameters are input/output parameters meaning they can be used for passing a value to a function as well as to get back a value from a function.We create a "ref" parameter by preceding the parameter data type with the ref modifier. When ever a "ref" parameter is passed a reference is passed to the function.
    using System;
    class ParameterTest
    {
    static void Mymethod(ref int Param1)
    {
    Param1=Param1 + 100;
    }
    static void Main()
    {
    int Myvalue=5;
    MyMethod(Myvalue);
    Console.WriteLine(ref Myvalue);
    }
    }
    Output of the above program would be 105 since the "ref" parameter acts as both input and output. Note
    The modifier "ref" should precede the parameter being passed even in the calling part. "ref" parameters should be assigned a value before using it to call a method.

    4.Params parameters "params" parameters is a very useful feature in C#‎. "params" parameter are used when a variable number of arguments need to be passed.The "params" should be a single dimensional or a jagged array.
    using System;
    class ParameterTest
    {
    static int Sum(params int[] Param1)
    {
    int val=0;
    foreach(int P in Param1)
    {
    val=val+P;
    }
    return val;
    }
    static void Main()
    {
    Console.WriteLine(Sum(1,2,3));
    Console.WriteLine(Sum(1,2,3,4,5));
    }
    }
    Output of the above program would be 6 and 15. Note
    The value passed for a "params" parameter can be either comma separated value list or a single dimensional array. "params" parameters are input only.
    ...مرا به خانه ام ببر، اگرچه خانه؛ خانه نیست

تاپیک های مشابه

  1. OverLoad Function
    نوشته شده توسط Business Analyst در بخش VB.NET
    پاسخ: 8
    آخرین پست: شنبه 21 مهر 1386, 21:26 عصر
  2. No overload for method اشکال در کلاس
    نوشته شده توسط am_abbas65 در بخش C#‎‎
    پاسخ: 3
    آخرین پست: شنبه 22 اردیبهشت 1386, 03:08 صبح
  3. OverLoad
    نوشته شده توسط champion در بخش برنامه نویسی در Delphi
    پاسخ: 4
    آخرین پست: جمعه 27 مرداد 1385, 11:19 صبح
  4. Overload و Override در ++C
    نوشته شده توسط saeedIRHA در بخش برنامه نویسی با زبان C و ++C
    پاسخ: 4
    آخرین پست: چهارشنبه 03 خرداد 1385, 10:52 صبح

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •