|
Aha! But that's done on purpose-- I intentionally duplicated exactly what his code would be doing if it used a StringBuilder. Every instantiation and method call. And as Mike Dimmick pointed out, StringBuilder has certain issues that should be considered.
Regards,
Jeff Varszegi
|
|
|
|
|
I just tested, and even avoiding the extra object creation by resetting the same StringBuilder each time, the StringBuilder solution only improves about ten percent, still about exactly twice as slow as the original poster's preferred method. I can post the code if you want, but I figure it's a snap for you to test yourself if you still don't believe me.
Regards,
Jeff Varszegi
|
|
|
|
|
It's not that I don't believe you, it's just that you were using the StringBuilder "incorrectly". I know that in some cases his preferred way may be better, but in most cases - apparently not this one - it is. Instead of continually calling Append , too, you can also use AppendFormat . I really don't care to see what the difference is, though, I'm just trying to make a point. AppendFormat is, after all, what String.Format is using so I know there's a lot of instructions required that search for the format parameter indexes and apply any format specifications using information from the Type that is in that parameter position, such as checking for IFormattable or using the IFormatProvider to get ICustomFormatter implementations for a specific type.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
It's really no problem. I'm just a speed freak when it comes to my code, and I'm constantly fiddling around to see what works fastest, sort of an object-oriented hot rodder. Wotta geek, eh? It's just my thing. I don't claim to be an all-around .NET expert, just pretty good with language features. Some of the questions you answer immediately on this board would take me a while.
I tend to use StringBuilder more now only when constructing large strings (although when I first made the jump from Java I used it religiously). It gives really good performance and lets you write your code in a normal way, without breaking lines. Every time I create one, though, I'm in the habit of just throwing it away; I figure that the bigger the string and related work, the less and less the instantiation of one object matters. Not only that, but if you construct strings of different sizes, and you get a really big one once in a while, I believe the internal char array of a StringBuilder will never shrink, which in some cases could be a problem.
Regards,
Jeff Varszegi
|
|
|
|
|
It just hit me that I might have intentionally confused people. There's loop unrolling in the posted code; I just copied it from an old project and modified. I think that the JIT compiler does its own loop unrolling, so it'd probably turn out about the same, but I unroll loops out of habit sometimes when benchmarking. Guess that makes me a dinosaur, eh?
Regards,
Jeff Varszegi
|
|
|
|
|
Hello,
I have created a TreeView that works fine apart from I can't work on how to get rid of the plus sign and line on the root node.
Does anyone know how to do this? Perhaps it isn't possible?
Thanks,
Matt
Matt Daley
Imutome Limited
Bristol, United Kingdom
matt.daley@imutome.com
|
|
|
|
|
I think you want to set the TreeView's ShowRootLines property to false . Untested suggestion.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Opps, Sorry, I forgot to mention that this is a WebControl TreeView, not the Web Form one. The Web Form TreeView has a ShowRootLines property but the WebControl one doesn't.
Matt
Matt Daley
Imutome Limited
Bristol, United Kingdom
matt.daley@imutome.com
|
|
|
|
|
Hello,
I'm wondering, what should I read about if I want to make a bandwidth monitor? And for just making sure what I mean with a bandwidth monitor I mean I want to show how much a user has downloaded and uploaded and how much (fast) he/she is uploading download at the current time =)
Any links? Articles?
I don't need articles specific for making a bandwidth monitor just subjects that when I know them I will proberbly be able to do a bandwidth monitor.
Thanks in advance dear code project members! =)
Martin Lundberg
Student, Sweden
I have to thank every member of the Code Project for making it such a great place for a beginner to learn!
|
|
|
|
|
Yes, I have one here on CP i did ages back, still using it everyday. Search for MyDUMeter.
|
|
|
|
|
Thanks, I'll look into that! =) Do you have any topics that will learn me how to do it myself? I know I can look at your code and try to understand but I would like some article where they explain how things work =)
~~~~~~~~~~~~~~
Martin Lundberg
Student, Sweden
I have to thank every member of the Code Project for making it such a great place for a beginner to learn!
|
|
|
|
|
|
argh! =P what about some articles? =)
|
|
|
|
|
My project form are added dynamic,How are to load these forms by form name , like this.
Form f = new Form(“FormName”);
Thank you
|
|
|
|
|
Hi Richard. This almost looks like MS Access Basic syntax . In C#, forms are objects just like everything else, and are instantiated with their class name. If I have a form called "DocForm" in my project, I could add an instance of this form at runtime with the following:
DocForm f = new DocForm();
f.Show() Was this what you meant?
|
|
|
|
|
You can use reflection. A primitive implementation would be like this:
Type t = Type.GetType("FormName");<br />
Form f = (Form) Activator.CreateInstance(t);
That of course depends on what you mean with "forms are added dynamically", if the specified type is in the same assembly where the above code is executing, it should work.
|
|
|
|
|
Thank both of you!
The second answer is What I wanted,I have test it works.
Following is my test code
///---------------------------------------------------------------------------
private void button1_Click(object sender, System.EventArgs e)
{
Module[] moduleArray;
moduleArray = Assembly.GetExecutingAssembly().GetModules(false);
//In a simple project with only one module, the module at index
// 0 will be the module containing these classes.
Module myModule = moduleArray[0];
Type myType;
myType = myModule.GetType("WindowsApplication1.Form2");
Form f = (Form) Activator.CreateInstance(myType);
f.Show();
}
///-------------------------------------------------------------------------
///-------------------------------------------------------------------------
|
|
|
|
|
Hi Richard. I think I misunderstood what you were looking to do. I'm glad you got the information you needed from Baris' post.
|
|
|
|
|
DateTime dt = DateTime.Now
gives me american date and not the british format d/m/y
i need the d/m/y
please
|
|
|
|
|
Internal representation of the DateTime object is not culture specific. It's the way you format it in ToString method.
DateTime.Now.ToString("dd/MM/yyyy");
note the capital MM if you put mm you will get minutes not the current month.
|
|
|
|
|
fantastic, i also noted in control panel (XP) a setting with American Language but I never knew about the ToString parameter very useful
|
|
|
|
|
This is also useful when using String.Format or Console.WriteLine . See the DateTimeFormatInfo documentation for more information, as well as my article, Custom String Formatting in .NET[^] for much more information, as well as links to other resources in the .NET Framework SDK.
Formatting strings properly in .NET is good to know.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
did you see my code about the error today a copy of my Tabpage class wonder if you have any thoughts
|
|
|
|
|
Also, read the docs for the CultureInfo class. If you need to convert dates and times from one culture to another, you can use the current CultureInfo as well as a specified culture and use their Calendar property to help convert. Also, if you are creating international applications, it's better to use DateTime.UtcNow to get the coordinated universal time.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Is there a way to get the scrollinfo of the TreeView?
I have tried PInvoke but doens't seem to work. Anyone sheds the light?
below are my codes
using System.Runtime.InteropServices;
public struct SCROLLINFO
{
uint cbSize;
uint fMask;
int nMin;
int nMax;
uint nPage;
int nPos;
int nTrackPos;
}
[DllImport("user32")] public static extern int GetScrollInfo(IntPtr hwnd, int n, ref SCROLLINFO lpScrollInfo);
//calling part
const int SB_VERT = 1;
SCROLLINFO si = new SCROLLINFO();
GetScrollInfo(this.tvStat.Handle, SB_VERT, ref si);
//the si return is all zeros. Doesn't work apparently
thanx
<B>Sonork 100.41263:Anthony_Yio
Life is about experiencing ... </B>
|
|
|
|