|
Calculating the end is expensive but, you always know when it starts.
class Program
{
static void Main(string[] args)
{
bool isFirst = true;
Primes myPrimes = new Primes(2,1000);
foreach (long i in myPrimes)
{
if (isFirst)
{
Console.Write(i.ToString());
isFirst = false;
}
else
{
Console.Write(", {0}",i.ToString());
}
}
if (!isFirst) Console.Write(".");
Console.ReadKey();
}
}
|
|
|
|
|
humayunlalzad wrote: (i==myPrimes.max )?".":",");
I would do this one of two ways
1 - write the first prime without a comma, then write them all with a leading comma. This means not using foreach, just a for loop.
2 - write the whole thing using a string builder, then use string mashing to remove/replace the last comma before writing to the console.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Did you read my response from when you posted this earlier?
|
|
|
|
|
I didn't spot that he's asking this over and over.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I notice a bug in you constructor: public Primes(long i, long j)
when called with i < 2 min will NOT be set to 2.
Philip Painter
|
|
|
|
|
Hello all,
I am new to programming and was wandering if I should learn with out a gui first or just command line.
thanks
|
|
|
|
|
Most programmers start off learning how to manipulate console(or command line) programs. However, developing a GUI in the past has been a much more difficult and tedious process.. With the introduction of drag and drop development environments, programming windows forms has become exponentially easier. But, I'd still start off learning simple black box console programs.
(If you're referring to developing without an IDE, that's how I started. But, it's not the easy way. Command line compilers like to puke unreadable syntax errors and exceptions at you. I had college professors to help me decipher.)
-- modified at 17:50 Friday 24th August, 2007
|
|
|
|
|
If, by "with out a gui" you mean; without an IDE, I'd say, no, definitely use an IDE (Visual Studio perhaps). But starting out writing console applications with that IDE is a very good idea.
|
|
|
|
|
No, he plainly doesn't mean that. He means should he write console or GUI programs.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Naw, you gotta do the typical "Hello World" first, which would be GUI.
Definitely use a visual IDE to develop your code.
Gary
|
|
|
|
|
If you have enough time start with GUI then commandLine and then GUI forever.
|
|
|
|
|
humayunlalzad wrote: start with GUI then commandLine and then GUI forever.
Why?
And GUI forever is not valid. There are many types of program, not all require a GUI. (A windows service, for example)
-- Always write code as if the maintenance programmer were an axe murderer who knows where you live.
Upcoming FREE developer events:
* Glasgow: Agile in the Enterprise Vs. ISVs, Mock Objects, SQL Server CLR Integration, Reporting Services, db4o ...
* Reading: SQL Bits
My website
|
|
|
|
|
Write command line programs first. If you do, you'll be streets ahead of most other people learning today, who learn by playing with the forms designer, and have big holes in their knowledge as a result.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thanks for the answers
I will continue to use SharpDevelop since vs2005 is to much dough
ugh boring command line lol
oh well I will search for some good tutorials...
anyone like sharpdeveoplemt or vs2005 (rich folks lol)
|
|
|
|
|
|
My advice is twofold:
- download Visual Studio Express Edition, it is free and it works really well;
- buy at least one up-to-date introductory book on the programming language of your
choice, make sure the book targets Windows and if it relies on a specific IDE it better be
Visual Studio; and then work your way through the book to make sure you fully understand
the language; it will teach you the most important classes, and it will probably
show you how to do console apps first, windows apps later.
At first, don't try to figure it all out yourself, let the book be your guide !
It will be much much faster, and much more thorough at the same time.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Stick with learning just the language via the console. Learning with a GUI will distract you from learning the fundamentals. You need to crawl (console) before you walk (GUI).
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Thanks for all the input on command vs gui for noobs...
also thanks for the express edition link
much appreciated and if you have any wisdom regarding programming please share
Thanks alot
Mark Nooby programmer
|
|
|
|
|
If you were new to programming and starting with C++ I would suggest a non-GUI application. However C# is made for the GUI interface and makes learning GUI programming very easy. Still, the approach for commandline programs in C# and C++ is quite a bit different.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios[ ^]
|
|
|
|
|
Yes, you are right. In C++ and C++/CLI, you can write a simple program inside of the main function. However, C# requires you write your simple program inside of a class inside of a static method. Thus, a new programmer has to contend with OOP at the start before learning about the fundamentals such as variable scope and iteration. When you add the GUI in the picture, you are dropping a lot of learning overhead that overwhelms many new programmers. Thus, they may miss learning what they really need to be solid programmers.
In a nutshell, keep it simple and build on a solid base. Fancy GUI programming can be learned later with the fundamentals under their belts.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
I have two ArrayLists, about 120 nodes in length. Each node contains a struct that contains about 24 variables. I want to easily compare the two ArrayLists. Am I going to have to create a method that simply goes through every node of both lists, comparing every variable? That seems tedious. Any help would be appreciated. Thanks
|
|
|
|
|
One method to compare one node to another, returning True or False.
One method to traverse the ArrayLists, passing the two nodes for comparison to method #1.
Now you can modify method #2 to traverse sequentially, compare 1 node of one array against all of the second array, etc., etc. Method #2 does not change.
Gary
|
|
|
|
|
For two ArrayLists A and B it all depends on how you define equality:
1. do you require the same number of elements? if so, check that first.
2. do you require the elements to be present in the same order? if so, just read through
both lists at the same time, and compare A[i] with B[i].
3. if not, first sort both lists according to whatever rule you can come up with that
defines a unique order, then go back to 2.
4. if you would allow for doubles then after sorting, remove (or skip) the doubles.
5. if you don't want to sort, you basically must compare N items of A with N items of B,
which is a quadratic job; you can improve a bit by removing the items you discover
are the same (copy them into two new ArrayLists). This reduces the job by a factor of 2
That's all.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
I am very new and trying to do something very advanced.
Can you open a file with StreamReader, format with StringBuilder, and then pass the results of the StringBuilder to a StringCollection? or am I out of my mind.
Here is my StringBuilder routine;
----------------------------------
public static string LayoutInput(string input)
{
StreamReader sr = File.OpenText(input);
StringBuilder sb = new StringBuilder(input.Length);
bool firstLine = true;
string line;
while ((line = sr.ReadLine()) != null)
{
if (line.Trim() == "")
continue;
if (line.Length < 29) { throw new InvalidOperationException("invalid input"); }
if (line[29] != ' ')
{
int txPos;
int rxPos = -1;
int len = 0;
if (firstLine)
firstLine = false;
else
sb.Append("\r\n");
if (((txPos = line.IndexOf("TX")) > -1) || ((rxPos = line.IndexOf("RX")) > 0))
{
int charactersTillPoint;
if (txPos > -1)
{
charactersTillPoint = txPos;
len = line.Substring(txPos).Length;
}
else
{
charactersTillPoint = rxPos;
len = line.Substring(rxPos).Length;
}
string part0 = line.Substring(0, charactersTillPoint);
string part1 = line.Substring(charactersTillPoint);
sb.Append(part0.PadRight(86));
sb.Append(part1);
}
else
sb.Append(line);
sb.Append(' ');
if (len == 12)
sb.Append(' ');
}
else
{
sb.Append(line.Substring(31));
}
}
return sb.ToString();
}
#endregion
}
----------------------------------
And here is my StringCollection Routine;
----------------------------------
StringCollection ReadFileIntoStringCollection()
{
const int MaxBytes = 65536;
StreamReader sr = new StreamReader(chosenFile);
StringCollection result = new StringCollection();
int nBytesRead = 0;
string nextLine;
while ((nextLine = sr.ReadLine()) != null)
{
nBytesRead += nextLine.Length;
if (nBytesRead > MaxBytes)
break;
result.Add(nextLine);
}
sr.Close();
return result;
----------------------------------
|
|
|
|
|
it seems from your second method you need to parse your string from string builder to lines like what you read from the Stream Am I right?
if it is what you need you can do with Split method from string instances like
string s = "hello \r\n how are you? \r\n";
string[] sArr = s.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
StringCollection col = new StringCollection();
col.AddRange(sArr);
it was the easiest way with least code change
however your methods are not efficient you can add your string to StringCollection instance instead of writing sb.Append("/r/n")
hope the post would be useful
good luck
|
|
|
|