使用一个类创建多个对象. [英] Using a class to create multiple objects.

查看:103
本文介绍了使用一个类创建多个对象.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确信答案很简单.我正在学习有关C#和XNA游戏开发的3D嗡嗡声课程.因此,我对编程总体还是陌生的.我了解到,通过一个类,您可以创建一个对象并赋予该对象属性,但是我们只是从控制台的角度来做到这一点.我们创建了自己的对象.我想做的是设置一个定义按钮的类.一个标准的Windows按钮.但是我不知道如何告诉这个对象它确实是一个按钮.我想我要问的是在GUI上创建一个定义按钮的类的正确方法是什么,我可以多次使用该按钮并具有多个副本,而不必手动编码每个按钮.只需将类重用为"Spawn "更多的?谢谢.

I am sure the answer to this is pretty simple. I am in the middle of a course from 3D buzz about C# and XNA game development. So I am new to programming in general. I have learned that with a class you can create an object and give that object properties but we have only done this from a console standpoint. And we created our own objects. What I am trying to do is setup a class that defines a button. A standard windows button. But I do not know how to tell this object that it is indeed a button. I guess what I am asking is what is the correct way to create a class that defines a button on a GUI that I can use multiple times and have multiple copies of without having to manually code every button in. Just reuse the class to "Spawn" more? Thanks.

推荐答案

有一个按钮类,为什么您会创建一个新的按钮类?

任何类都是工厂,您可以创建一个名为"frog"的类,然后创建多个"frog"类型的变量.这应该是您上课的核心.要创建作为控件的类,请从Control类派生它,以便框架知道它是控件,并可以将其视为控件.阅读有关自定义控件的文章可能是一个不错的起点,但是您可能会发现您可以使用或修改现有的按钮类.
There is a button class, why on earth would you create a new one ?

Any class is a factory, you can create a class called ''frog'', then create multiple variables of type ''frog''. This should have been at the core of the class you took. To create a class that is a control, derive it from the Control class, so that the framework knows it is a control, and can treat it as such. Reading articles on custom controls is probably a good place to start, but you may find that you can just use, or modify the existing button classes.


类是一种类型.这意味着它用于通过定义定义多个对象(此类应为非静态).什么是多份复印件"?为什么?

我认为您没有掌握编程的精髓.没有人需要同一个对象的多个副本.需要多个对象不同.但是,如果您有两个引用类型的对象,则与 value类型相比,copy语句将创建对同一对象的另一个引用:值类型的对象的副本将创建对象本身的副本.在进行XNA编程并询问关于按钮的完全不清楚的问题之前,您确实需要学习基础知识.学习基础知识的最佳工具是开发非常小巧的控制台应用程序.从此开始:阅读一本语言和.NET手册,并通过简单的练习将其阅读到最后.

在理解类型系统,类(甚至没有OOP),结构及其成员,变量(堆栈,静态,成员—),方法和方法参数以及所有传递它们的方法之前,请不要尝试开发任何东西. >
请参阅我过去的回答:我有问题我的程序.请帮忙! [
A class is a type. It means it is used to define multiple objects by definition (such class should be non-static). What is "multiple copies" and why?

I think you''re not getting a very essence of programming. Nobody needs multiple copies of the same object. Multiple objects are needed to be different. However, if you have two objects of reference type a copy statement creates another reference to the same object, in contrast to value type: a copy of the object of value type creates a copy of the object itself. Before getting XNA programming and asking completely unclear questions about buttons, you really need to learn basics. The best tool for learning basics is development of really small and simple console application. Start from this: take a language and .NET manual and read it to the end doing simple exercises.

Don''t try to develop anything before you understand type systems, classes (even without OOP), structures and their members, variables (stack, static, members—), methods and method parameters with all method of passing them.

See my past answer: I have a problem with my program. Please help![^].

—SA


这篇关于使用一个类创建多个对象.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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