Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hallo all,
I want to create new function like below:

C#
public static Bitmap TapisKotak(Bitmap Img,int Width,int Hight,int StartX,int StartY, int RowsY,int ColumnX)
{
    bitmap Img_process=new bitmap(Img);
    int New_Coordinat_X, New_Coordinat_Y;
    //process here and I get that I want... so i return the image modified (image object) and any value in int variable

    return(bitmap Img_process);   //==> this object image
    return(New_Coordinat_X);      //==> this int value 1
    return(New_Coordinat_Y);     //==> this int value 2
}


on this code I want to return multiple value including object and numeric value. how to do it on C#????
thanks for help.
Posted
Updated 7-May-18 2:17am
v2

Script? Are you serious? C# is not a scripting language.

There are a number of ways to return two object from one function. You can return one as usual return and another one as out parameter. You can create some type (class or structure) with two members (object and numeric) and return an object of this type. Alternatively, you can use an already defined generic type with two members. Such type, in particular, it Tuple:
http://msdn.microsoft.com/en-us/library/system.tuple.aspx[^].

—SA
 
Share this answer
 
Comments
JayantaChatterjee 13-Apr-13 22:52pm    
My 5...
Sergey Alexandrovich Kryukov 13-Apr-13 23:12pm    
Thank you, Jayanta.
—SA
bagus bujangga 14-Apr-13 0:07am    
thank you Sergey, I read this Tuple article now.
Sergey Alexandrovich Kryukov 14-Apr-13 1:13am    
Sure. I would think you can accept the answer formally (green button).
—SA
Thomas Daniels 14-Apr-13 3:53am    
+5!
Inside the same assembly you can use anon types:


C#
public static dynamic TapisKotak(Bitmap Img,int Width,int Hight,int StartX,int StartY, int RowsY,int ColumnX)
{
    bitmap Img_process=new bitmap(Img);
    int New_Coordinat_X, New_Coordinat_Y;
    //process here and I get that I want... so i return the image modified (image object) and any value in int variable

    return new {Image = Img_process, X = New_Coordinat_X, Y = New_Coordinat_Y};
}
 
Share this answer
 
Comments
bagus bujangga 14-Apr-13 0:06am    
thanks, but how to call??

Bitmap Test = Class.TapisKotak(bla, bla,bla,....) ?
Try This man
C#
public void CallFuntion()
{
  //your code
   var Return = TapisKotak(Img, width, Heigth, StartX, StartY, RowsY, ColumnX)
   bitmap img_processed = Return.Img;
   int New_Coordinat_X = Return.X;
   int New_Coordinat_Y = Return.Y;
   //Now you have all values returned!
}

public static (Bitmap Img, int X, int Y) TapisKotak(Bitmap Img,int Width,int Hight,int StartX,int StartY, int RowsY,int ColumnX)
{
    bitmap Img_process=new bitmap(Img);
    int New_Coordinat_X, New_Coordinat_Y;
    //process here and I get that I want... so i return the image modified (image object) and any value in int variable

    return (Img_process, New_Coordinat_X, New_Coordinat_Y);
}
 
Share this answer
 
v4
Use tuple or use out parameters.
 
Share this answer
 
public static IEnumerator TapisKotak(Bitmap Img,int Width,int Hight,int StartX,int StartY, int RowsY,int ColumnX)<br />
{<br />
    bitmap Img_process=new bitmap(Img);<br />
    int New_Coordinat_X, New_Coordinat_Y;<br />
    //process here and I get that I want... so i return the image modified (image object) and any value in int variable<br />
<br />
    yield return bitmap Img_process;   //==> this object image<br />
    yield return New_Coordinat_X;      //==> this int value 1<br />
    yield return New_Coordinat_Y;     //==> this int value 2<br />
}
 
Share this answer
 
Comments
Maciej Los 7-May-18 8:23am    
Why to answer already answered question?
BTW: 5 years too late!
GuilhermeAlencar 14-May-18 13:19pm    
Because it is not just one person in the world who will need this answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900