I am rewriting a vb.net app and I can't claim to be great with vb. I need to write this equivilent in C#:
Dim bigList = (From gme In dtx.gmc_message_elements
Where gme.element_key_name Like "*email" _
Or gme.element_key_name Like "*web"
Or gme.element_key_name Like "*both" _
Select gme.element_key_name Distinct).ToList()
I have so far:
var bigList = (from gme in dtx.gmc_message_elements
where gme.element_key_name Like "*email"
|| gme.element_key_name Like "*web"
|| gme.element_key_name Like "*both"
select gme.element_key_name).FirstOrDefault().ToList();
As you can see I am not sure what the equivalent of the like operator is. I ran this through a couple code converters and they constantly threw errors.
To get the most equivalent functionality ensure your C# project has a reference to the Microsoft.VisualBasic assembly.
You can then directly use the VB.NET Like
operator from your C#, e.g.
LikeOperator.LikeString(gme.element_key_name, "*web", CompareMethod.Text);
Be sure to include the
using Microsoft.VisualBasic.CompilerServices;
This will get the most equivalent functionality, however would be what I consider a bit of a hack.
Your other options would be to make use of the String.StartsWith
, String.EndsWith
, String.Contains
or Regex.
Use StartsWith
or EndsWith
or Contains
static methods of string
based on your needs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With