C# for Configurator user defined method

I am trying to put a method that will detect whether a text input has a “/” and/or a “.”, to understand whether the user input a fraction or a decimal. I want to define a subroutine HasIt, that returns the position of the sought character in the string or 0 if not found:

int HasIt(string strInput, string Delimiter)

The code compiles nicely in visual studio, but, in Epicor I get a CS1528 error : cannot specify constructor arguments in declaration. The web has not been helpful so far. Does anyone know anything about this?

Could you post a screen shot of the parameter definitions for the UD method?

Assuming your UD method as two ref parameters and a return type of int you would just do this. Some of this syntax depends on version and where calling from.
EDIT: I see now that you posted code you are doing something different

//Could use in evaluation for integer position
HasIt(ref strInput, ref Delimiter) ;
// assign to variable
int Position = HasIt(ref strInput, ref Delimiter);

Hi Evan.
Yes, I have attached below the parameter definition of the UD method as well as the code I am trying to get to work. It’s deadly simple but…

I think its the starting and ending brackets, try removing them.

The UD method is called LengthFraction. It has only one parameter, strInput, which represents the text the user has keyed in.
The LengthFraction UD method has within it the HasIt subroutine, with the two parameters : the string to be searched, and the delimiter.
When I remove the “int” in front of the HasIt declaration, I get an error CS0103, saying the name “HasIt” does not exist in the current context…

I would also try changing your internal function “HasIt” to a lambda function instead of a local function. I haven’t tried local functions in Epicor, but I am pretty sure I have used lambda functions fine.

I take it you meant the brackets enveloping the entire UD method. I removed them. Same result….

Hi Evan, just saw your post suggesting to use a lambda function instead of a local function. I will look this up as I am not familiar with the term and see if this can solve the problem. Thank you.

int add(int x, int y) => x + y;  // local function format
Func<int, int, int> add = (x, y) => x + y; //lambda format

Ok… will try that…:slight_smile:

Syntax is correct !!! Yeah!
Now, hopefully, it will do what’s expected.

Thank you so much Evan!

Glad it worked. I think local functions were added in c# 7, not sure what version Epicor uses. In your case a local function would be better, but a lambda is just fine too.

Don’t forget to mark the answer. :grinning:

1 Like

So am I Evan. I don’t know how to mark the answer, so I clicked on the “like” button, and also checked that it solved the problem. If this is not what you meant, let me know, and I will mark it the proper way!

1 Like

Mark as solved was what I meant, thanks.