我可以将字符串添加到某些内容而不是数据库中吗? [英] can I add a string to something rather than a database?

查看:66
本文介绍了我可以将字符串添加到某些内容而不是数据库中吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们还没有在学校学习数据库;数据库是我们预计在明年提出的更高主题.

但是我是一个即将到来的程序员,我应该首先对简单的东西有更多的了解.
我现在正在视觉C#上工作,我可以将名称(字符串)添加到某个变量.

但这不是实际的应用.一个只可以保存一个字符串,hmph的应用程序,一个小孩子...我只需要使用工具箱中的某些对象,并且我必须编写某些代码,以便可以在其中保存很多名称.

我的问题是,我必须使用什么对象,并且双击它应该写什么代码(以使它很有趣地在最后添加字符串).

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 ).

推荐答案

是的,您可以将字符串添加到某些内容中.至于将名称(字符串)添加到某个变量" –这根本没有意义.没有这样的概念.例如,您可以将字符串追加到字符串.是使问题我应该写什么对象"无关紧要.如果您真的不知道想要什么,没有对象可以为您提供帮助.就是那一刻,你没有.

看起来您需要更进一步,并几乎从一开始就开始学习编程:变量,对象和类型,编译时间和运行时间,作用域和生命周期等.请意识到严格术语的重要性.您需要获得有关C#的基本手册,并完整阅读所有内容,而无需跳过任何内容,在代码中进行最简单的练习,随时随地学习.NET的基础.

尝试从以前的回答中遵循我的基本指示:
我的程序有问题.请帮忙! [
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


您不应使用工具箱中的任何内容...
使用
列表 [ IList [泛型 [
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:
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);


该代码基本上说您有一个要在其中添加名称的字符串列表.
然后,您检查列表中的每个名称并将其写入控制台(或您喜欢的任何名称).
要存储更复杂的数据,可以使用Classes.


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.


这篇关于我可以将字符串添加到某些内容而不是数据库中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆