|
mav.northwind wrote:
Using "" doesn't require this lookup, so it should be _a wee little bit_ faster,
Here is the optimized JIT code. Same thing... except with "" you will be adding more strings to the string table of the assembly.
16: string a = "";
0000000f mov eax,dword ptr ds:[01AA1010h]
00000015 mov esi,eax
17: string b = string.Empty;
00000017 mov eax,dword ptr ds:[01AA2014h]
0000001c mov edi,eax
xacc-ide 0.0.15 now with C#, MSIL, C, XML, ASP.NET, Nemerle, MyXaml and HLSL coloring - Screenshots
|
|
|
|
|
I expected it to be very little difference in the compiled code, but I didn't expect it to be as good as no difference at all.
Anyway, regardless of how it is currently implemented, the code that best resembles your intention will often be the most efficient. The compiler will be able to optimize the code better if the information you give it is better. In some future implementation or on a different system, using string.Empty might even be the most efficient way.
---
b { font-weight: normal; }
|
|
|
|
|
mav.northwind wrote:
Using "" will be marginally faster because the runtime doesn't have to look up a constant, but I strongly doubt that you will notice a difference in real life.
If you look at the difference in the IL, string.Empty almost sounds faster.
ldstr ""
vs.
ldsfld string [mscorlib]System.String::Empty
With ldstr , it's pushing an object reference to a string literal stored in the metabase onto the stack where as ldsfld pushes the value of a static field onto the stack.
mav.northwind wrote:
But I think it's more important to keep an eye on good readability than to try and tune execution speed by replacing string.Empty with "".
I completely agree.
|
|
|
|
|
On a related note, if you're checking to see whether a string is empty, it is more efficient to use
if(str.Length == 0)
instead of
if(str == "") or if(str == string.Empty)
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Cops & Robbers
Judah Himango
|
|
|
|
|
|
Hi everybody.
I open a Word document in the web browser control, I then select some text in it using a mouse, and I want to paste the selected text into another text box on the same form, but it does not work.
The code looks like this:
Clipboard.SetDataObject("");
_web.Focus();
_web.ExecWB(SHDocVw.OLECMDID.OLECMDID_COPY, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER,ref refmissing , ref refmissing);
IDataObject iData = Clipboard.GetDataObject();
if(iData.GetDataPresent(DataFormats.Text))
{
textBox2.Text = (String)iData.GetData(DataFormats.Text);
}
It is as if the selected text gets copied somewhere else. I did an extensive search on the web, but to no avail.
Sending keys to the browser control will get no results, like:
_web.Focus();
SendKeys.Send("^c");
Nothing in the clipboard aftert that operation either.
Thanks a lot.
Sarajevo, Bosnia
|
|
|
|
|
Hi guys,
I wanna get all handles (particularly files) opened by a process. I can get the HandleCount property of 'Process' object but don't know how to access those handles from .NET classes . I guess i have to use P/Invoke to access win32 APIs where kind of EnumHandles() function has to be used. I need a code example in this connection or if it's possible using .NET framework classes.
Thanx
|
|
|
|
|
There is no function to enumerate open handles.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I have been to over 7 C# sharp websites, gotnet,c-sharp, even the ones microsoft recommended, even microsoft website was poorly done. Does, anyone know any good websites that have huge ammount of memembers and projects to choice from for C#?...i am getting tired of only having to choose 1 more a list of 4.
|
|
|
|
|
Anonymous wrote:
Does, anyone know any good websites that have huge ammount of memembers and projects to choice from for C#?
Welcome to the CodeProject, take a look around!
|
|
|
|
|
HI To All,
i want to print string (English & Arabic) in the same line but when i write arabic string the arabic string allign in the right
For Example:
input befor printing: فى الصفحة Printing هذه تجربة
output after printing: Printing فى الصفحة هذه تجربة
|
|
|
|
|
I need a code which gives me the function name which call the another function.
Example :- there are two classes.
CA and CB. CB inherits CA. I want a code which gives me the name of class CB and its function name when i call the function of CA.
--Navdeep
|
|
|
|
|
I'm not entirely sure I understand what you are asking for. Are you interested in a StrackFrame relative to the caller or are you wanting to perform reflection against a type?
|
|
|
|
|
Write a regular expression pattern to match:
1. a full URL (for ex :http://www.yourcompany.com/index.htm )
2. Human name (case sensitive) for ex : Jonh Smith
Plz help me to answer this problem
Thanks very much.
I tried so hard and got so far
|
|
|
|
|
There are website out there that have all sorts of regex expressions. Hint: search for "regular expression library" or something similar.
Alex Korchemniy
|
|
|
|
|
Is this your homework?
---
b { font-weight: normal; }
|
|
|
|
|
URL: how about this one: http://www.foad.org/~abigail/Perl/url3.regex[^]? Though you could shorten it a bit if you only want http and not check for every detail...
Human name (case sensitive): This is not possible (or equally complicated to url3.regex) because names are different in every country. You want that every 'word' starts with an uppercase letter? Then your regex won't work for many non-English names that have some sort of 'filling word' between first and last name.
|
|
|
|
|
Hi
I have to do a program in c# windows application such that form employs with a textbox, Progress bar, label and abutton.
I have to use system.threading.timer such that , when a time is given in the textbox, (say 02:30 PM),then the progress bar progresses and at last after progress bar finishes , the label which is in the form should turn red colour at that specified time(ie, 02:30 PM)..
How o do this .Please help me to do this application.
js
|
|
|
|
|
The Timer class doesn't kick off at a specified time. Rather, it counts down from a specified number of milliseconds and fires it's event. It then resets itself and repeatedly fires its event on that interval.
If you want to check for a certain time, then you'll have to use a Timer to kick off code every minutes or so and check the current system time against your scheduled time. When the times match, then you can launch your process.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
i would like to know how to use the mouse events.
just the same things that thecodeproject.com uses for "message boards" link etc...
suggest me any good online tutorial or give one or two simple examples.the rest i will explore
jyothipradeep
|
|
|
|
|
hi there,
take a look on this
http://www.codeproject.com/cs/miscctrl/MouseEvents.asp
<< >>
|
|
|
|
|
I am trying to program an owner-drawn tabcontrol. I am trying to enable the user of my tabcontrol the ability to specify a text color for the selected tab so that the selected tab stands out better.
I have overridden the OnDrawItem method and am receiving the events just fine, but my problem is determining what tab that the OnDrawItem method is being called for.
I just can't figure out how to take an x,y coordinate and turn it into which tab it corresponds to (expecially taking into account that there may be multiple rows of tabs and the tabs may be on the top or side of the tab control, etc).
Any help would be greatly appreciated!
Darryl Borden
Principal IT Analyst
dborden@eprod.com
|
|
|
|
|
Never mind - I figured it out. It is passed as "Index" in the event args object!
dpb
Darryl Borden
Principal IT Analyst
dborden@eprod.com
|
|
|
|
|
I want to display a month calender in which only saturdays can be clicked on and highlighted and also how can i acquire all the saturdays in a month?
Thanks
VisionTec
|
|
|
|
|
The windows month calendar control is very weak and not flexible. The only thing you can really do is catch date changed and check if it's a saturday. You can do much more than that.
>> How can i acquire all the saturdays in a month?
math + DateTime class
Alex Korchemniy
|
|
|
|