Click here to Skip to main content
15,886,801 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
We haven't learn database at school ; database is a higher subject we suppose to take in the next year.

But I'm an upcoming programmer and I should know more about simple things first.
I'm working on visual C# right now, and I can add a name (string) to a certain variable.

But that's not a practical application ; an application that can save only one string, hmph, what a kid..I just have to use something, some object from the toolbox...and I must write a certain code so it can save lots of names in it.

My question is, what is the object I must use, and what code should I write when I just double click on it (to make it funtion adding strings in the end ).
Posted
Comments
theanil 30-Jun-11 16:59pm    
You can save it in a text file...

Yes, you can add a string to something. As to "add a name (string) to a certain variable" — this simply makes no sense. There is no such notion. You can append a string to string, for example. Is makes the question "what object should I write" irrelevant. No object can help you if you don't really know what you want. It the moment, you don't.

It looks like you need to take even bigger step back and start learning about programming nearly from the very beginning: variables, objects and types, compile time and run time, scope and life time, etc. Please realize importance of strict terminology. You need to get some elementary manual on C# and read it all without skipping anything, doing most simple exercises in code, learn basics of .NET as you go.

Try to follow my basic directions from my former answers:
I have a problem with my program. Please help![^].

—SA
 
Share this answer
 
v2
Comments
Sander Rossel 30-Jun-11 17:06pm    
A good answer. I was just not sure if the OP said stuff like "what object should I write" because of total lack of skill or because English is not his main language and he couldn't find another way to express himself. If he is in school I suspect he knows SOMETHING... Wait, I almost forgot the most stupid Q&A questions are homework assignments... :)
Sergey Alexandrovich Kryukov 30-Jun-11 23:12pm    
Thank you, Naerling.

Just one note -- about knowing "something" because being taught at school. Did you face such phenomena -- purely negative knowledge?

(Adam, please don't think I'm talking about you. I don't mean you, just sharing my experience with kind some students/engineers.)

Few years ago a friend of mine brought to my attention that in some type of people schooling does not give them anything useful no matter how hard they learn and even how successfully they pass exams (sometimes quite successfully). School only makes it worse because it creates an illusion of extra knowledge in addition to the exact same ignorance which existed before school. Nearly zero knowledge becomes even worse -- negative. I was amazed but to my surprise observed some cases of this phenomena. Such people often graduate, demonstrating spectacular failure of examination system. I observed this illness in people with PhD degree and some rare cases with the degree higher than that...

--SA
Sander Rossel 1-Jul-11 3:30am    
Unfortunately that is so true. Kind of how I felt when I graduated... "What the hell did I learn in here? I better start learning something useful..." so then I became a programmer. Reading some books and hanging around on CP in my spare time thaught me more in one year than I could've learned from any school in four years. My trust in the schooling system is 0.0.
Seeing as your solution got accepted and mine didn't even get a vote I think you were right in that the OP did indeed not know about Classes, Generics, Lists or anything of the sort. Makes you wonder what these kids do at school... :s
You should not use anything from your ToolBox...
Use a List[^], or rather anything that Implements IList[^], just what meets your wishes.
It requires some knowledge of Generics[^] though. But once you get it you can simply do something like the following:
C#
List<string> names = new List<String>();
names.Add("John");
names.Add("Doe");

// Or consider the following Button.Click EventHandler...
private List<String> _names
private void Button1_Click(Object sender, EventArgs e)
{
   if _names is null
      _names = new List<String>();
   
   names.Add(TextBox1.Text);
}

// To loop through the names use a for each loop.
foreach (String name in _names)
   Console.WriteLine(name);

That code basically says you have a list of strings which you add names to.
You then check every name in the list and write them to the console (or anything you like).
To store more complex data you can use Classes.
 
Share this answer
 
v6
Comments
Sergey Alexandrovich Kryukov 30-Jun-11 17:00pm    
Looking at the degree of OP's confusion, I'm not sure this is applicable. The OP's problems are deeper.

Please see my answer.
--SA
Sergey Alexandrovich Kryukov 30-Jun-11 17:03pm    
I fixed your formatting. You cannot use angular brackets in HTML as you did, I replaced it with &lt; and &gt; tags and removed parasitic tags created by the HTML post processing, it fixed formatting.
--SA
Sander Rossel 30-Jun-11 17:07pm    
Thanks, another reason to write VB! ;p
Philippe Mori 30-Jun-11 21:49pm    
Last 3 lines starting with // Ignore these /string thigies... could be erased. If something like this come back it is because you should replace <string> by &lt;string&gt;
Sergey Alexandrovich Kryukov 3-Jul-11 0:29am    
True. I've done it, fixed another <string> and capitalization.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900