Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# function Multi
Hallo all,
I want to create new function like below:
 
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 13-Apr-13 17:08pm
Edited 13-Apr-13 19:04pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
Comments
Jayanta Chatterjee at 13-Apr-13 22:52pm
   
My 5...
Sergey Alexandrovich Kryukov at 13-Apr-13 23:12pm
   
Thank you, Jayanta.
—SA
bagus bujangga at 14-Apr-13 0:07am
   
thank you Sergey, I read this Tuple article now.
Sergey Alexandrovich Kryukov at 14-Apr-13 1:13am
   
Sure. I would think you can accept the answer formally (green button).
—SA
ProgramFOX at 14-Apr-13 3:53am
   
+5!
Sergey Alexandrovich Kryukov at 14-Apr-13 14:59pm
   
Thank you,
—SA
bagus bujangga at 14-Apr-13 6:36am
   
Yes, I can use Tuple to resolve my problem
thank you Sergey Alexandrovich :D
Sergey Alexandrovich Kryukov at 14-Apr-13 15:00pm
   
You are welcome.
Good luck, call again.
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Inside the same assembly you can use anon types:
 

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};
}
  Permalink  
Comments
bagus bujangga at 14-Apr-13 0:06am
   
thanks, but how to call??
 
Bitmap Test = Class.TapisKotak(bla, bla,bla,....) ?

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



Advertise | Privacy | Mobile
Web04 | 2.8.1411022.1 | Last Updated 14 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100