return value from class

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

  • : 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.

Howdy, Stranger!

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

Categories

In this Discussion