|
Yes, when it gets scaled up it is a problem. I think then that you have to come up with a hashing scheme which preserves your sort order, and use that as the key instead. The only other way I can think of immediately is to use an unsorted list, and sort it by model. Yeuch.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Hi,
the content of the "model" string, i.e. the actual characters, are stored only once. What is stored twice is the reference to the string, which takes 4 or 8 bytes depending on Win32/Win64; so the penalty for having the key also in the struct is very low.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
|
I'd forgotten that (still not completely used to managed code hiding the details).
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Actually, you would only have redundant references to the Product model string when using the SortedList<K, T> type. The model string is not actually duplicated in memory. While I've never done any performance analysis of SortedList or any of the other .NET collection types, I think what you are doing now is probably your best solution.
If this isn't acceptable and you can use .NET 3.5, you could use LINQ to create a sorted List<T> that would only include your Product structs.
IList<Product> sl = (from p in ul
orderby p.model
select p).ToList<Product>();
|
|
|
|
|
What I'm looking is a source code to show me how to make and use menus. Here's a
sample of what I have. and Some of it works and some of it doesn't
--------------------------------------------------------
//Main Menu
MainMenu:
terminal.ClearScreen();
terminal.WriteLine();
terminal.WriteLine("Welcome :" + name);
terminal.WriteLine("1) Game Menu");
terminal.WriteLine("2) N/A");
terminal.WriteLine("3) Help");
terminal.WriteLine("9) Quit");
terminal.TranslateFile("Menu.txt", true);
terminal.Write("Choice : (1,2,3 0r 9)");
int caseSwitch = terminal.ReadDigit();
switch (caseSwitch)
{
case 1:
Functions NewGame = new Functions();
NewGame.GameMenu();
goto MainMenu;
case 2:
terminal.WriteLine("Case 2");
goto MainMenu;
case 9:
break;
default:
terminal.WriteLine("Invalid Key");
terminal.PromptEnter("Press ENTER to Continue..");
goto MainMenu;
}
------------------------------------------------
|
|
|
|
|
bigjoe11a wrote: Some of it works and some of it doesn't
Are we supposed to guess which parts work and which don't?
Every time you use a goto a kitten gets punched in the face. Why do you hate kittens so much?
|
|
|
|
|
Ok, why not. LOL. I mean it doesn't work at all. When I press 1. it just returns to the menu. and so on. Or the default just loads.
DO you know of a sample source code that will show me how to do this the right way.
--------------------------------------------------------------------
MainMenu:
terminal.ClearScreen();
terminal.WriteLine();
terminal.WriteLine("Welcome :" + name);
terminal.WriteLine("1) Game Menu");
terminal.WriteLine("2) List Users");
terminal.WriteLine("3) Help");
terminal.WriteLine("9) Quit");
terminal.Write("Choice : (1,2,3 0r 9)");
int caseSwitch = terminal.ReadDigit();
switch (caseSwitch)
{
case 1:
Functions NewGame = new Functions();
NewGame.GameMenu();
goto MainMenu;
case 2:
terminal.WriteLine("Case 2");
goto MainMenu;
case 3:
Functions NewHelp = new Functions();
NewHelp.Help();
goto MainMenu;
case 9:
break;
default:
terminal.WriteLine("Invalid Key");
terminal.PromptEnter("Press ENTER to Continue..");
goto MainMenu;
}
-----------------------------------------
|
|
|
|
|
Seriously, goto s are the biggest indicator in the world of poorly structured code. Code flow should be handle by conditionals and loops and I'm guessing that's the main cause of your problems. My beginners attempt would start like this:
Semi-Psuedo Code:
bool done = false;
while (!done)
{
int userInput = 0;
do
{
PrintMainMenu();
userInput = GetNextInput();
} while (!InputIsValid(userInput));
switch (userInput)
{
case 0:
PrintHelpMenu();
break;
case 1:
RunGamesMenu();
break;
case 2:
Console.WriteLine("Exiting");
done = true;
break;
}
}
P.S. put pre tags around code snippets to preserve formatting
|
|
|
|
|
Thanks, Can you give me an idea about what the PrintMainMenu would look like and a sample of the code used to make it. Or make be I'm getting to old to program.
Thanks
|
|
|
|
|
it would contain something like this (from your original post):
terminal.ClearScreen();
terminal.WriteLine();
terminal.WriteLine("Welcome :" + name);
terminal.WriteLine("1) Game Menu");
terminal.WriteLine("2) N/A");
terminal.WriteLine("3) Help");
terminal.WriteLine("9) Quit");
I just stuck a function there to save space in the post
|
|
|
|
|
Rule 1: Use the "code block" button below to preserve formatting. It makes things easier to read.
Rule 2: unless you are a seriously experienced programmer and there is a very good reason, do not use goto. It will earn you nothing but grief and abuse here.
Rule 3: Learn about loops. Learn about data types. Learn at least the basics of C#.
Rule 4: Learn there is a difference between "Console" and "Terminal" (one exists, the other doesn't)
Having said that, I'm in a good mood:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Demo
{
class Program
{
static void Main(string[] args)
{
string name;
Console.Write("Enter your name: ");
name = Console.ReadLine();
Console.WriteLine("\nWelcome : " + name);
Console.WriteLine("1) Game Menu");
Console.WriteLine("2) List Users");
Console.WriteLine("3) Help");
Console.WriteLine("9) Quit");
Console.Write("Choice : (1,2,3 or 9) ");
int i = 0;
do
{
string s = Console.ReadLine();
if (s == "")
{
continue;
}
i = s[0];
switch (i)
{
case '1':
Console.WriteLine("Game selected");
break;
case '2':
Console.WriteLine("List selected");
break;
case '3':
Console.WriteLine("Help selected");
break;
case '9':
Console.WriteLine("Quit selected");
break;
default:
Console.WriteLine("Invalid Key");
break;
}
}
while (i != '9');
}
}
}
This is not perfect (I threw it together from your code), but it has the advantage of working...
Now, for your homework, please post a complete explaination of how it works.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
>>Now, for your homework, please post a complete explaination of how it works
Home work. Grin. I haven't done any home work in over 30+ years. and to explaination of how it works. ? I have no idea. It mite take some time before I can even under stand what you did. Any chance I can get you to make a simple one.
|
|
|
|
|
Oooo! That is a simple one!
I can't teach you C# - I haven't got the time - but I'll do what I can.
Have you got any tools yet (C# compiler, etc)? If not, go to microsoft.com and search for "C# 2008 Express download" - this will give you a free copy of the C# IDE, with all the tools you need to do nearly everything with C#.
Do get a book on C# - there are some good ones out there, but I am not sure what you would need for starters. There is a free one available here C# Yellow book[^] which is used by the University of Hull for 1st year CS students and should cover the language basics.
Now, what have we got:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Demo
{
class Program
{
static void Main(string[] args)
{
...
}
}
}
This is all overhead - it is automatically generated for you and provides a "framework" in which your program can run.
string name;
Console.Write("Enter your name: ");
name = Console.ReadLine();
All this does is declare a variable called "name" that can hold a string of text, prompt the user for his name, and read his response.
Console.WriteLine("\nWelcome :" + name);
Console.WriteLine("1) Game Menu");
Console.WriteLine("2) List Users");
Console.WriteLine("3) Help");
Console.WriteLine("9) Quit");
Console.Write("Choice : (1,2,3 or 9) ");
Print out the users selection of choices.
int i = 0;
do
{
...
}
while (i != '9');
This sets up a loop - the program will go around and around here until the variable "i" contains the value '9', then it will exit the loop.
string s = Console.ReadLine();
if (s == "")
{
continue;
}
Read the users menu selection into the variable "s", check that he didn't just press the ENTER key (if he did, ignore it and got back around the loop).
i = s[0];
switch (i)
{
case '1':
Console.WriteLine("Game selected");
break;
case '2':
Console.WriteLine("List selected");
break;
case '3':
Console.WriteLine("Help selected");
break;
case '9':
Console.WriteLine("Quit selected");
break;
default:
Console.WriteLine("Invalid Key");
break;
}
Get the first character of the users input into the variable "i" (not a nice way, but it matched your code) and decide what to do with it. The "switch (i)" line says "look at the contents of the variable 'i', and compare it against the examples I will give you. If you find one which matches, then perform the instructions between the ':' character and the word 'break'"
'//' says "whatever text is to the right of me, ignore it, it is just a comment for poeple to read rather than an instruction for the computer".
Hope this helps a bit - it is really difficult to know where to start!
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Hi! OriginalGriff,
Thank you very much. That was very easy for me to understand. It works. Thank You
Can you tell me how to make the loop into a hot key. Where the user doesn't have to press enter. Just the number
Thanks
Joe
|
|
|
|
|
Replace
string s = Console.ReadLine();
if (s == "")
{
continue;
}
i = s[0];
with
ConsoleKeyInfo cki;
cki = Console.ReadKey(true);
i = (int) cki.Key;
(the "true" prevents the key being echoed to the display.)
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Thank you very much. That works
|
|
|
|
|
I take it you spotted that one then...
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
|
Hello,
How can i activate the mouse whell scroll in a datagrid?
|
|
|
|
|
Your question doesn't make any sense.
"Activate the mouse"?? What does that mean??
|
|
|
|
|
Hello,
I have windows application with tabpages and datagrids.
When i resize the windows size (to full screen) the window resizes but the tabpages and datagrids no.
How can i do that all of them will be resized according the original window size?
|
|
|
|
|
you could look into the Anchor property of the controls. That might do what you want but depending on the layout of your controls you might have to do with code called on the forms resize event.
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
You can use Dock and Anchor properties.
|
|
|
|
|
Guys
When I run two instances of notepad, while task manager is running, I see that the number of processes increases with each instance of notepad or any exe. It means they are running in their own process and appdomain respectively. How can I make two programs run on different appdomains but the same process.
|
|
|
|