Click here to Skip to main content
15,905,144 members
Please Sign up or sign in to vote.
1.24/5 (3 votes)
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

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?
 
Share this answer
 
You're "returning" something from your method, which cannot be "void". Replace "void" with the "type" of the object you're returning.
 
Share this answer
 
Comments
Member 14169626 6-Jan-20 14:50pm    
necessarily return value. So how do I?
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.
 
Share this answer
 
Change your method to

public string GenerateBacode(string _barcodedata)
{
return _barcodedata;
}
 
Share 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