This question already has answers here:
C#7: Underscore ( _ ) & Star ( * ) in Out variable
(6 answers)
Discard feature significance in C# 7.0?
(7 answers)
Closed 3 years ago.
First of it all: my C# Knowledge is depricated because i do other projects in the meantime.
So i come back and see whats up now, but there is one thing i do not understand.
This is now valid in C#
_ = new object();
I try to use a search engine of my choice but u can imagine search for "C# _" isnt very helpful to search for. Can someone explain whats going on here? My idea was this is placeholder to pop the result back on the stack and avoid agressive compiler optimization. But at the end, i have no idea.
Related
This question already has answers here:
C# Empty Statement
(13 answers)
Closed 5 years ago.
I've come across this example of an empty statement in a C# textbook.
Code:
public void empty()
{
;
}
Some quick googling found that it's a redundant feature and I can't see the use of this as it seems pointless?
I was curious to know when this would've been useful and if it's still used to date even though it's obsolete?
In the given example it is pointless and/or cosmetic.
The empty statement is "useful" in places where a statement is required but you have nothing to do, like
while (condition_with_side_effects) ;
Because of the side effects required, this will not match with most coding guidelines or best practices.
Consider it a leftover from C.
This question already has answers here:
What is the difference between const and readonly in C#?
(30 answers)
Closed 6 years ago.
I come from a C++ background and am trying to become proficient in C#. It seems like C# always has 2 types of modifiers wherever C++ had one. For example, in C++ there is & for references and then in C# there is ref and out and I have to learn the subtle differences between them. Same with readonly and const, which are the topic of this thread. Can someone explain to me what the subtle differences are between the 2? Maybe show me a situation where I accidentally use the wrong one and my code breaks.
Readonly: Can only be set in the constructor.
Const: Is a COMPILE TIME CONSTANT. I.e. can not be determined at runtime.
This question already has answers here:
What's the difference between [Something] and [SomethingAttribute] [duplicate]
(3 answers)
Closed 7 years ago.
I hope this wasn't asked already. But i found nothing. If something exists, thanks for the note.
The title says it all i think.
I've seen these two variants. But in my opinion it does the same. And why can i use both. Thanks for education.
// variant 1
[ContentProperty("Text")]
// variant 2
[ContentPropertyAttribute("Text")]
You can omit the word "Attribute" when writing attributes over something. The actual class is called ContentPropertyAttribute. Both of your lines do exactly the same and use the exact same attribute 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:
Closed 12 years ago.
Possible Duplicate:
Is there a method that will evaluate a string and produce an integer (assuming the string is an equation) in C#
Hi all, i just wonder how to make a realtime complination in C#
For example: i have a string like this
string math = "1 + 2 + (4 - 6)";
And i want to complie it to get the result
How to do that? and is that the bad idea because i want to make a calculator in C#?
Edited:
The main question properly is that i want to do it in WP7, not exactly in C# windows lol, i tried all the solutions below but not at all is correct!
and is that the bad idea because i want to make a calculator in C#?
One problem with that is that your calculator language is probably supposed to be just a subset of C#. So using the C# compiler may be too flexible and allow arbitrary C#. Kind of like problems with SQL injection attacks.
Expresion Evalution is an application of STACK (Data Structure)
You can see these link If you want Sample projects
http://www.vbforums.com/showthread.php?t=397264
http://www.codeproject.com/KB/cs/runtime_eval.aspx
http://www.c-sharpcorner.com/uploadfile/mgold/codedomcalculator08082005003253am/codedomcalculator.aspx