将int附加到对象名称 [英] appending an int to objects name
本文介绍了将int附加到对象名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只想在对象名称中添加一个int
我怎样才能实现
例如: - classname obj1;
下一个对象
classname obj2;
等.....
i编程错误
解决方案
为什么?
你可以做到 - 这不简单,但你可以做到。问题是它必须在运行时完成 - 这意味着你不能引用项目中的名称(因为它们在编译时不存在)。
相反,我建议您使用数组或类实例的集合,并通过索引器访问它们:例如myobjects [1]。
听起来你想要的是一个阵列 [ ^ ]。
还有一种方法可以做到这一点使用一种名为令牌粘贴 [ ^ 一>]。
i just want to add an int to the name of the object
how can i achieve that
eg:- classname obj1;
next object
classname obj2;
so on.....
i am bad in programming
解决方案
Why?
You can do it - it's not simple, but you can do it. The problem is that it has to be done at run time - which means that you can't refer to the names in your project (because they don't exist at compile time).
Instead, I would suggest that you use an array or a collection of your class instances, and access them via the indexer : myobjects[1] for example.
It sounds like what you want is an array[^].
There is also a way to do this kind of thing with the preprocessor, using a technique called token pasting[^].
这篇关于将int附加到对象名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文