C# Equivalent to VB6 Chr(number) [duplicate] - c#

This question already has answers here:
What's the equivalent of VB's Asc() and Chr() functions in C#?
(12 answers)
Closed 8 years ago.
I have this code:
Dim sCenter As String
sCenter = Chr(27) + Chr(97) + Chr(1)
And I'm trying to convert to a C# code. Online converters always fail to convert... :(
So, what is the C# equivalente of Chr(number)?
Maybe Char.ConvertFromUtf32(10);

Feel like taking risk to answer but how about?
string sCenter;
sCenter = "" + (char)27 + (char)97 + (char)1;
Thanks to James Curran's comment about char integral addition. As his suggested, I added meaningless "" with char to get string + char which uses .ToString() with String.Concat method at background.

Related

Unexpected character '$' [duplicate]

This question already has answers here:
How do I interpolate strings?
(15 answers)
Closed 5 years ago.
HttpResponseMessage response = await client.PutAsJsonAsync($"api/products/{product.Id}", product);
In the above code I've been using the $ keyword but I don't the significance of this keyword. I searched in google but coiuldn't find proper answer. I think this might be a duplicate but couldn't find relative answer even in stackexchange.
Thanks in advance
It's an interpolated string - the new feature of C# 6, which is basically just a syntax sugar for String.Format (compiler converts interpolated strings into the String.Format calls). Your string is equivalent to
String.Format("api/products/{0}", product.Id)
$"api/products/{product.Id}"
is the short version for
string.Format("api/products/{0}", product.Id);
You could have a look in the MSDN

Replacing ' " ' in a string [duplicate]

This question already has answers here:
How to replace straight quotation mark (")
(3 answers)
Closed 6 years ago.
Some string variables have a " in the data which recks with my php code. I want to take it out in my C# code before the data gets passed to php. I just can't remember the way of doing it, but I tried with this :
line.Replace(#""", "");
This is not correct in Xamarin, what is the good syntax?
I guess this would work.
line.replace("\"","");
use \ to escape it.
line.Replace("\"", "");

What the meaning of " (!0) " in ILNumerics Library? [duplicate]

This question already has answers here:
Why is !0 a type in Microsoft Intermediate Language (MSIL)?
(2 answers)
Closed 6 years ago.
What the meaning of " (!0) " in ILNumerics just like this
return (!0)ILMathInternal.exp(this.m_mu);
and like this,
return 0.5 + (!0)ILMathInternal.log(this.m_sigma) + this.m_mu + (!0)ILMathInternal.log(ILMathInternal.sqrt(2.0 * ILMathInternal.pi));
Why we use this kind of expression---"(!0)" ?
(!0) has no meaning, it is not valid C#
If I had to guess, which I do, I suspect the (!0) is how a decompiler has chosen to represent some IL code that has no C# representation.

How to decode ' in c# [duplicate]

This question already has answers here:
Remove or Convert ' to (')
(3 answers)
Closed 7 years ago.
I found a similar question on how to decode ^#39; or simply ' in php, but I have been having trouble finding a way of decoding that value in c#. Thoughts? I have been trying the following in my code...
agenda.MeetingLocation = agenda.MeetingLocation.Replace("'", "''")
However, the value in my form field is John Doe's test. The value I see for agenda.MeetingLocation is:
John Doe's test
(the ^ is a &)
This should work if it's encoded like "& #39;" instead of "^#39;". Are you sure your input uses "^"?
System.Web.HttpUtility.HtmlDecode("John Doe's test.");

VBA to C# with statement [duplicate]

This question already has answers here:
With block equivalent in C#?
(19 answers)
Closed 9 years ago.
I am trying to convert simple vba "with statemnt" to C#. ProductRangeA and B are named ranges. Could someone to give a hint?
With ProductRangeA
myRow= .Rows.Count:
myValue= .Value
End With
With ProductRangeB
myRow= .Columns.Count:
myValue= .Value
End With
As HighCore said, there's no C# equivalent to VB's With block. Here's the equivalent C# code:
myRow = ProductRangeA.Rows.Count;
myValue = ProductRangeA.Value;
myRow = ProductRangeB.Columns.Count;
myValue = ProductRangeB.Value;
Since you can't avoid typing ProductRangeA and ProductRangeB twice each, you can reduce typing by using shorter variable names. That can make the code more difficult to understand, of course.

Categories