|
hello,
Can anyone recommend one or two C# articles on CodeProject which you think has very good/professional code, is well-documented, uses good design, follows .NET coding guidelines, etc.
I'm looking for some examples of well written and complete classes/controls/etc that I can learn from to improve my own code.
|
|
|
|
|
Search for Marc Clifton's articles. Sometimes it can be confused in the beginning cause Marc understand a lot of C#, but if you read paying attention, the Marc's articles are great. There are a lot of great article writers, I prefer Marc.
Another good article writer is Xiangyang Liu.
I like of their styles, they are very professional in their articles. It's my opinion.
|
|
|
|
|
Thanks Alex,
I'll take a look at those articles...
|
|
|
|
|
Hi,
Please clarify which is more efficient.
using string.Empty or "". If so please explain why is this.
Iam often getting confused on this.
Thanks.
|
|
|
|
|
Hi!
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.
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 "".
Regards,
mav
|
|
|
|
|
But both string.Empty and "" will be constants. The only difference is where they are declared. The constant for string.Empty already exists, so there are hardly any point of creating more constants that are identical.
---
b { font-weight: normal; }
|
|
|
|
|
Not entirely correct, I think. I looked it up in IL.
Using the constant
string.Empty
compiles to
ldsfld string [mscorlib]System.String::Empty
whereas using
""
yields
ldstr ""
So I'd assume the runtime would have to check at least once whether mscorlib is loaded already (which is, of course) to be able to access a constant defined in a type from this assembly.
Using "" doesn't require this lookup, so it should be _a wee little bit_ faster, but, as I wrote, I don't think you'll be able to notice it.
Regards,
mav
|
|
|
|
|
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
|
|
|
|