This question already exists:
Closed 11 years ago.
Possible Duplicate:
String vs string in C#
I have a test in C# code I'm reading:
if (variable is string)
I am wondering if this is strictly equivalent to:
if (variable is String)
or if some esoteric behavior of C# autoboxing may cause these tests to behave differently.
They are exactly the same - string is an alias for System.String.
Related
This question already has answers here:
Evaluating string "3*(4+2)" yield int 18 [duplicate]
(13 answers)
Is there a string math evaluator in .NET?
(18 answers)
Closed 4 years ago.
I have one scenario in C#, which I fetch the expression from database, I need to parse and evaluate the same
The expression can be of any type (With + & - Operator only) as mentioned below
X+Y-Z
X-Y-Z
Z-Y+Z
Where as at run time I have any of above expression as string item and the values for each variable defined in it.
Now I need to automate the same, so that my code at run time will able to parse and evaluate the same.
I believe Switch case and if/else loop is the one way, but any can please suggest some other better and efficient way.
Thanks in advance
This question already has answers here:
String interning in .Net Framework - What are the benefits and when to use interning
(5 answers)
String Interning
(4 answers)
Why some identical strings are not interned in .NET?
(5 answers)
Can two identical strings be two separate instances in C#?
(3 answers)
Intern string literals misunderstanding?
(2 answers)
Closed 5 years ago.
Consider the following code snippet in C#
string s = "hi";
object k="hi".Substring(0);
// 1>
k==s // true
// 2>
Object.ReferenceEquals(s,k) //true
but when,
Object k="hii".Substring(0,2);
// 1>
k==s // false
// 2>
Object.ReferenceEquals(s,k) //false
I am having difficulty understanding why in the first case, the strings were interned while it doesn't happen so in the second case.
Also it would be very helpful if anyone can point out the rules when string interning happens in c#.
This question already has answers here:
What's the use/meaning of the # character in variable names in C#?
(9 answers)
Closed 7 years ago.
So I was digging through some code and I saw something along these lines.
Func<T> #delegate = ...
My question is what is the # operator used for in this case?
I've seen it used when creating string literals but never when referencing something other than a string.
Func<T> is a generic delegate in C#.
delegate is a reserved word in C# so the developer prefixed it with # to use it as a valid variable name.
You will see it in asp.net MVC project for HTML helpers where for setting class we use #class as class is a reserved word in C# so we can't have a variable with name class
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.
This question already has answers here:
How do I get a consistent byte representation of strings in C# without manually specifying an encoding?
(41 answers)
Determine a string's encoding in C#
(10 answers)
How to find out the Encoding of a File? C#
(5 answers)
Closed 9 years ago.
I saw this answer, The problem is - so I also need to know what type of encoder to use for getting the correct string - it may be in UTF\UTF8\ANSI.
Here is a example from the immediate window.
Encoding.Unicode.GetString(combinedBuf)
"믯ힿ힜힕�"
Encoding.UTF8.GetString(combinedBuf)
"שלום"