Click here to Skip to main content
14,580,625 members
Rate this:
Please Sign up or sign in to vote.
See more:
I'm generating a barcode value in a method.And I want to get this value according to the values ​​in the foreach. How can I call the value of the method that returns the value.
public void GenerateBacode(string _barcodedata)
 {
    return _barcodedata
 };


What I have tried:

foreach(var _a in Clothes)
{
if( xx < 5)
{
     tshirt.Add(new Clothes()
    {
       Clothes_Color="Blue",
       Clothes_SaveType=1,
       Clothes_Barcode=GenerateBarcode();   //// This line is error generated barcode can not write value

     }
}

}
Posted
Updated 7-Jan-20 2:26am
v2
Rate this:
Please Sign up or sign in to vote.

Solution 2

You have to match the signature of the method when you are calling it. Here:

  1. you should define the return type of the method (string instead of void) as already stated in solution 1.
  2. you defined the method as having a single string argument, but you do not provide any when you call it.

All these mistakes should generate errors in the IDE anyway, and you should not be able to compile because of them.
There also seems to be an issue with the naming: Clothes seems to represent a class and a collection of objects at the same time.
Maybe you need to get back to c#/OOP 101, and grasp these essential notions?
   
Rate this:
Please Sign up or sign in to vote.

Solution 1

You're "returning" something from your method, which cannot be "void". Replace "void" with the "type" of the object you're returning.
   
Comments
Member 14169626 6-Jan-20 14:50pm
   
necessarily return value. So how do I?
Rate this:
Please Sign up or sign in to vote.

Solution 3

Your
GenerateBacode
method is void, thus can not return anything, at leas via return value. Give this method a return type which suite for your needs.

This probably a bad typo, but you define
GenerateBacode
however you call the
GenerateBarcode
method.

And a last one hint. You wrote "barcode can not write value", if I'm correct, then you can not assign value to left side of equal sign. Maybe that member is a readonly field or simply a "getter" property.
   
Rate this:
Please Sign up or sign in to vote.

Solution 4

Change your method to

public string GenerateBacode(string _barcodedata)
{
return _barcodedata;
}
   

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




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