Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

return value from class

labbylabby Posts: 10Member
Hi,

I want get return value from a class and call it from the main programming code, but it return error. The error is :

ScanFirstStage: members name cannot be same as their enclosing type.
Could any help me please?

This is the class that suppose return the value -->

public int ScanFirstStage (Bitmap image, out int cb)
{

// get image size
int width = image.Width;
int height = image.Height;

pixels = width * height;
// lock bitmap data
BitmapData imgData = image.LockBits(
new Rectangle(0, 0, width, height),
ImageLockMode.ReadOnly,
PixelFormat.Format64bppPArgb);

int srcStride = imgData.Stride;
int srcOffset = srcStride - width;


// do the job
unsafe

{
byte* p = (byte*)imgData.Scan0.ToPointer();
int i = 0;

for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
if (*p == 0)
{
i++;
}

++p;
}

p += srcOffset;
}

cb = i;
}

// unlock image data
image.UnlockBits(imgData);

}

This is the code from mainform to call the return value -->

ClassFirstStage.ScanFirstStage filter3 = new ClassFirstStage.ScanFirstStage(binary, out scanning1);
//apply filter for extraction
double scan1 = filter3.ScanFirstStage;
int num1 = (int)scan1;
objectCount1.Text = num1.ToString();

Comments

  • GogiGogi Posts: 258Member
    : Hi,
    :
    : I want get return value from a class and call it from the main programming code, but it return error. The error is :
    :
    : ScanFirstStage: members name cannot be same as their enclosing type.
    : Could any help me please?
    :
    : This is the class that suppose return the value -->
    :
    : public int ScanFirstStage (Bitmap image, out int cb)
    : {
    :
    : // get image size
    : int width = image.Width;
    : int height = image.Height;
    :
    : pixels = width * height;
    : // lock bitmap data
    : BitmapData imgData = image.LockBits(
    : new Rectangle(0, 0, width, height),
    : ImageLockMode.ReadOnly,
    : PixelFormat.Format64bppPArgb);
    :
    : int srcStride = imgData.Stride;
    : int srcOffset = srcStride - width;
    :
    :
    : // do the job
    : unsafe
    :
    : {
    : byte* p = (byte*)imgData.Scan0.ToPointer();
    : int i = 0;
    :
    : for (int y = 0; y < height; y++)
    : {
    : for (int x = 0; x < width; x++)
    : {
    : if (*p == 0)
    : {
    : i++;
    : }
    :
    : ++p;
    : }
    :
    : p += srcOffset;
    : }
    :
    : cb = i;
    : }
    :
    : // unlock image data
    : image.UnlockBits(imgData);
    :
    : }
    :
    : This is the code from mainform to call the return value -->
    :
    : ClassFirstStage.ScanFirstStage filter3 = new ClassFirstStage.ScanFirstStage(binary, out scanning1);
    : //apply filter for extraction
    : double scan1 = filter3.ScanFirstStage;
    : int num1 = (int)scan1;
    : objectCount1.Text = num1.ToString();
    :
    :


    Hello,

    Seems like you have a class and a function in that class which have the same names.
    Example:
    You have class ScanFirstStage and function ScanFirstStage in that class.

    I hope it helps!

    Greetings from Gogi
Sign In or Register to comment.