|
Reelix wrote: And the (possible) answer YOU were looking for is one from further up...
Move the
sw1.Start();
JUST above the
// Touch Nothing Below Here
No, I have the sw1.Start(); at the top. No cheating.
Let's do it like this:
Stopwatch sw1 = new Stopwatch();
sw1.Start();
string largeString;
... code to populate the string here
if (largeString.Length == 500000) {
Console.WriteLine("Pass 1");
} else {
Console.WriteLine("Fail 1");
}
if (sw1.ElapsedMilliseconds < 1000) {
Console.WriteLine("Pass 2");
} else {
Console.WriteLine("Fail 2 - " + sw1.ElapsedMilliseconds);
}
bool pass = true;
for (int i = 0; i < 500000; i += 10) if (largeString.Substring(i, 10) != "1234567890") pass = false;
if (pass) {
Console.WriteLine("Pass 3");
} else {
Console.WriteLine("Fail 3");
}
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
|
No takers?
Here's how to do it really fast without a StringBuilder:
string shortString = "1234567890";
string miniString = string.Empty;
for (int i = 0; i < 125; i++) miniString += shortString;
largeString = string.Empty;
for (int i = 0; i < 15; i++) largeString += miniString;
for (int i = 0; i < 5; i++) largeString += largeString;
This runs in 2 ms on my computer, just as fast as using a StringBuilder.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Reminds me of the not-so-urban legend about the Chinese farmer who saved the emperors life and asked only one grain of rice in the first square of a chess board, twice that in the next square and so on for all 64 squares.
He obviously got his head chopped off once the emperor realized where things were going...
Later,
--
Peter
|
|
|
|
|
Change the first two lines to this:
Console.Write("Pass 1\nPass 2\n");
return;
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
You stole my answer.
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
|
|
|
|
|
The \n should be Environment.NewLine since it differs on different platforms.
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
Oh puh-lease! Exactly how many "platforms are you going to run a .Net app on? Ummmm, I predict ONE.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
I DID think someone would try something like
Console.WriteLine("Pass1\nPass2");
But it would crash the program...
Didn't think about return;
-= Reelix =-
|
|
|
|
|
Hi,
i'm having a problem with binding radiobuttons to bool properties of my own build class.
My class has 3 bool properties which are bound each to one radiobutton the Checked property. The 3 buttons are on the same panel so only one can be checked.
But it seems that selecting one of the radiobuttons has no effect. When i select one and go to another field/textbox) it jumps to the original value.
All other bindings to textboxes and checkboxes are good.
i'm working with VS2005, Dotnet 2.0.
Does anyone has any idea what goes wrong ?
Thx
Kurt
|
|
|
|
|
Good Day,
I am using BinaryFormatter to write my own file. The Formatter takes a STRUCT that I constructed and convert it to a byte array that I can write as file. However, for some strange reason, when the FILE is too large (200MB+), I get an out of memory exception. Here's the code:
public static byte[] RawSerialize(object anything)
{
MemoryStream Stream = new MemoryStream();
BinaryFormatter BF = new BinaryFormatter();
BF.Serialize(Stream, anything);
byte[] Data = Stream.ToArray();
return Data;
}
Please note that I have 3GB ram on my system and when the OOM error was called, my memory usage was only 20%.
Is there any workaround for this?
Thanks!
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.
|
|
|
|
|
Instead of dealing with in-memory byte arrays and streams, why not utilize the hard drive as the backing store stream? This way you won't have to load 200+ MB into memory.
Tech, life, family, faith: Give me a visit.
From my latest post: "It's sobering to watch: the whole country stops for 2 minutes as a siren is blast to remember the 22,437 victims of terror and soldiers who died in defense of Israel..."
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
Thanks for the reply Mr. Himango,
Can you please give a detail example or a link on how to accomplish such task? Or maybe just a hint.
Thanks!
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.
|
|
|
|
|
void SaveObjectToDisk(object objectToSave, string fileName)
{
using(FileStream file = File.Create(fileName))
{
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(file, anything);
}
} You'll want to look at MSDN for more info, they cover file I/O in great detail.
Tech, life, family, faith: Give me a visit.
From my latest post: "It's sobering to watch: the whole country stops for 2 minutes as a siren is blast to remember the 22,437 victims of terror and soldiers who died in defense of Israel..."
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
Hi all,
I have a dataset DsA and 1 datagridview DgvA . I have bind a dataset into DgvA and also add a combobox into DgvA accroding data in DsA .
I would like to know how can i refresh the comboBox in DgvA when DsA was edit?Below is the senario,
1)DsA have 5 rows and values are {a,b,c,d,e}
2)Add comboBox (which according data in DsA) to a datagridview
3)Add 5 rows in datagridview and a comboBox's value is select for each row ,as:
row 1: a
row 2: b
row 3: c
row 4: d
row 5: e
4)Edit row's value in DsA, now will be {W,X,Y,Z,Q}
5)Refresh value in datagridview will get the result as:
row 1: W
row 2: X
row 3: Y
row 4: Z
row 5: Q
Any tips/idea/related source are welcome.
Note: i will not only edit row in DsA, but also will add/delete row in DsA
Here is the exception which i get when DsA changed:
The following exception occured in the datagridview:
system.ArgumentException: DataGridViewComboBoxCell value is not valid
To replace this default dialog please handle the DataError event.
thanks in advance.
regards
cocoonwls
modified on Tuesday, May 20, 2008 11:09 AM
|
|
|
|
|
I was figure out how to do it in my application. Thanks for who have been view my question.
|
|
|
|
|
Hi All,
I want to convert text files (.doc,.txt..rtf) to pdf files using C#.Net.
if any one knows please send me the solution or how to do it.
Thanks in Advance
|
|
|
|
|
Asking someone to send you the code is a poor etiquette in programming forums.
The answer to your question is quite easy if you know how to use Google. Search for DOC to PDF converter. I know there are at least 1 open source tool and at least 4 commercial tools that do this.
Tech, life, family, faith: Give me a visit.
From my latest post: "It's sobering to watch: the whole country stops for 2 minutes as a siren is blast to remember the 22,437 victims of terror and soldiers who died in defense of Israel..."
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
Sophia Rekhi wrote: I want to convert text files (.doc,.txt..rtf) to pdf files using C#.Net.
As far as I know you would have to do a COM interop for this..
|
|
|
|
|
Hi All,
I am new to sharepoint concept. I am deploying custom webparts in to my sharepoint site. I deployed it using STSADM.exe but cannot group it into different categories. Can any one help me in this regard.
Expecting your reply
Cheers
Mani.
First have the WILL then u WILL
|
|
|
|
|
Don't cross post
led mike
|
|
|
|
|
under which topic should i post this question....
First have the WILL then u WILL
|
|
|
|
|
What is the .NET 3.5 redistributable package..
Does it contain the whole library needed to run any app??
I am planning to build an application in .NET which would require the framework obviously and when I ship this to client then I would have to ship the .NET framework too for it to run..
My question is that is the .NET 3.5 framework redistributable package which is freely downloadable on Microsoft site enough for shipping with my client application??
Since the size of the package is only 2.73MB, will the whole framework be installed with this redistributable package and would this be enough for my app to run??
One possibility may be that the client may not have an internet connection.. So would shipping this redistributable package be enough or does the client have to download the framework from internet after installing this 2.73MB package??
Please reply..
Thanks..
|
|
|
|
|
Hey,
Not sure, because I haven't deployed 3.5 stuff yet, but I think there's one with Windows SDK 6 (the one installed automatically with VS 2008).
Should be somethere here if you have VS 2008 installed: C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages\DotNetFX35
-- Everything is possible, even the impossible! ^_^
|
|
|
|
|
I've got a feeling that that 2.73MB installer is simply a bootstrapper which downloads the rest from the internet. At the moment the current framework weighs in at about 300MB, with SP1 (beta at the moment) Microsoft will be introducing a "cut-down" version (i.e. it excludes all the server stuff) which will bring the redistributable size back down to a few tens of megabytes.
I doubt it. If it isn't intuitive then we need to fix it. - Chris Maunder
|
|
|
|