What is the use of an empty statement [duplicate] - c#

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.

Related

c# brackets statement after semaphore.Wait() without condition or header [duplicate]

This question already has answers here:
Floating curly braces in C#
(6 answers)
Closed 6 years ago.
I came across the following code in c#:
semaphore.Wait();
{
HandleRateLimit(region);
}
semaphore.Release();
(source)
I was wondering, do the brackets around the HandleRateLimit(...) call have any special meaning? If not, why would someone write code that way?
Brackets have nothing to do with semaphores. The idea was, probably, to make it more readable and to point out critical section.

Difference between ContentPropertyAttribute and ContentProperty [duplicate]

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.

Whats the point of Tuple(Of T) [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
What's the purpose of the Tuple(T1)/Singleton in .net?
Trying to mimic a Tuple as implemented in .Net 4 (For .Net 3) I just realized there is a Tuple(Of T)? This was quite a surprize!
Why would anyone do this
Tuple<string> result = new Tuple<string>("Data");
Instead of this
return "Data";
Isn't the whole point of a tuple that its a container for "loosely related data that isnt cohesive enough to make another class"? Am I missing something?
There are a finite number of tuple-arities in the library, so to define an 8-tuple, you use the kind with 7-elements whose 'rest' argument is a one-tuple. See
http://msdn.microsoft.com/en-us/library/dd383325.aspx
This is a carry over from set theory that might not have much use for a software developer.
Tuples are simply ordered lists of elements. An N-tuple has n elements, and n can be one, which is called a singleton. You probably won't have much use for a 1-tuple in code, but I'm guessing the C# team put it in there for completeness.
http://en.wikipedia.org/wiki/Tuple#Etymology

Realtime complination in C# [duplicate]

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

C# - Which is faster: String.Contains() or Regex.isMatch()? [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Regex.IsMatch vs string.Contains
Which is faster, preferable and why?
What the difference in mechanisms between two?
I need to search for some values from UserAgent, most of values can be used without wildcards (e.g. if I want to catch cellular phones I search for iPhone instead of *iPhone* wildcards).
What is faster
Try measuring. But this is the wrong question, see below.
preferable
If I want to match a fixed string String.Contains does just what I need. If I need to pattern match, then String.Contains is useless.
Comparing the performance of these is irrelevant, they do completely different things. Use the right tool first, and only then if your performance is a problem use profiling to identify hot parts of your code to look at.

Categories