需要帮助C#上的案例 [英] Need help with case on C#

查看:103
本文介绍了需要帮助C#上的案例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们!



我想在文本框中写一个字符串,然后给它一个类似2的值。 (案例2 :)

在此之后,我想按一个按钮,在随机脚本之后得到我写的一个句子。我怎样才能实现这个目标?



类似于:

x = 0



如果点击按钮:

新案例?!

新增随机(1,x)



开关(x)

案例1:



案例2:



我我是新手。如果我可以帮助你进一步了解我的想法我会尽我所能...谢谢:)

解决方案

你可以使用将字符串与字符串关联的字典。然后你可以从那里查找它们。因此,将int设为键,存储字符串,跟踪您创建的int,然后查找它们。字典可能是在这个阶段要学习的稍微复杂的容器,但这就是你要做的事情


在C#中你有一组Collection类可以存储使用键或索引检索数据。



参考这些链接以了解有关收集类的更多信息。

http://msdn.microsoft.com/en-us/library/ms172181(v=vs.80) .aspx [ ^ ]

http: //msdn.microsoft.com/en-us/library/xfhwa508(v=vs.80).aspx [ ^ ]



定义任何集合应用程序中的类,用于在应用程序运行时处理字符串。



恢复字符串供以后使用你必须在关闭应用程序之前保存文件并在加载应用程序时读取文件。检查这个.txt文件。

http://www.csharp- examples.net/filestream-open-file/ [ ^ ]

Hey guys!

I''d like to write in a textbox a string and then give it a a value like "2". (Case 2:)
After this, I''d like to press a button and after a random script get one of the sentences i wrote. How can I achieve this?

Something like:
x=0

If button is clicked:
new case?!
new random(1,x)

Switch (x)
case 1:

case 2:

I am a newbie at this.. If I can help you to further understand my thought I''ll do my best... Thanks :)

解决方案

You can use a dictionary to associate ints with strings. Then you can look them up from there. So make the int the key, store the string, keep track of the ints you created, and look them up. A dictionary is perhaps a slightly complex container to learn about at this stage, but that''s how you''d do it


In C# you have set of Collection classes where you can store and retrieve data using a key or index.

refer these links to know more about Collection classes.
http://msdn.microsoft.com/en-us/library/ms172181(v=vs.80).aspx[^]
http://msdn.microsoft.com/en-us/library/xfhwa508(v=vs.80).aspx[^]

Define any of the collection class in your application to deal with the strings when the application is running.

to restore the strings for later use you must save the file before closing the application and read the file while loading your application. check this for working on .txt files.
http://www.csharp-examples.net/filestream-open-file/[^]


这篇关于需要帮助C#上的案例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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