Using the same variables (same code) in my IF condition, windows-legacy is throwing a compile error that appears to a type-mismatch, but the same code (if conditions) works perfectly on Windows version.
We would assume different misusages.
Can yout tell us the sample value from sheetName Variable?
Thanks
Looks like the split function is misused…if you see you are not providing any delimiter…only string input is provided
cheers
Screenshot shows its assignment and an example of its value. All other possible values in the FOR
“Added HCPCS Codes”
“Deleted HCPCS CPT Codes”
“Modified HCPCS Code Descriptions”
“Reason Key: A=Added To List, N=New Code”
We are not sure if the input or the output is meant and has the value deleted. We also do see a different construct, not same to the above screenshots
We do feel that a proper requirement/value would speed up the answer. However, let’s start.
Regardless if there are some passing validations, we would state
- When using First/FirstOrDefault Linq Operator and passing some arguments on it (i+1).toString) it is against the defined method signature. We do see the complained string received, but lambda with Boolean output is expected
Legacy:
EDITED: Thanks to @supermanPunch for bringing the new feature into the picture (post below)
vs. Windows:
-
Maybe the Idea was about returning a default string, when it is empty, which we can do with DefaultIfEmpty(“myString”)
[HowTo] LINQ - First Start # DefaultIfEmpty Operator -
the Split Function from the Strings ← was used:
Strings.Split(String, String, Int32, CompareMethod) Method (Microsoft.VisualBasic) | Microsoft Learn
where the split char can be optional, but we would assume a different goal was aimed
Example:
So more and more we risk drifting away from the needed output by the given input
Maybe you can elaborate more on what is given and what is needed. Thanks
@ppr Thanks for the input. Apologies, I have updated my reply to include the accurate value (see screenshot) of the variable sheetName . Does this new information help ?
full package is welcome
lets go another small step
sampling was done within the immediate panel ( you can also use)
A first() would extract Added or Reason. We guess that those values are not the expected SheetNames
Hi @yomi.oluwadara ,
The specification of Default value with FirstOrDefault()
should be possible with Windows versions but in the Legacy it is not possible, as for the Legacy projects, the .Net versions are lesser than .Net 6.
So, the replacement would be to use the Method as suggested by @ppr for Legacy Projects
@supermanPunch and @ppr
For this code to work in legacy, should the code:
sheetNamesAdded.Contains(Split(sheetName).FirstOrDefault((i+1).ToString)) = true
Should essentially become
sheetNamesAdded.Contains(Split(sheetName).DefaultIfEmpty()) = true ?
Looking at the resource Enumerable.DefaultIfEmpty Method (System.Linq) | Microsoft Learn , I would think invoking the DefaultIfEmpty() should work, but it does not
Could you let us know what did not work ? Was there a Compiler error like before or did it not return the Expected result ?
Let us know what is the Expectation from this change in code.
still we have doubts on the split part and what is tried
in addition to the LINQ training in legacy we can do
for demo purpose we did a where fitlering, with resulting empty filterresult, and returned the default value.
But your involved split construct will react as
Here is the error and attached is the windows legacy project itself.
regexTableProj.zip (690.2 KB)
I’m still confused about the error.
if we would rewrite to:
sheetNamesAdded.Contains(Split(sheetName).DefaultIfEmpty((i+1).toString()).First()) = true
we would adapt. But still we have doubts if implementation is matching expectation
@ppr and @supermanPunch The DefaultIfEmpty worked and I’m getting my expected behavior.Thanks
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.