如何在编译时设置什么类型的对象集合保存 [英] how to set at compile time that what type of objects collection holds

查看:52
本文介绍了如何在编译时设置什么类型的对象集合保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我已将排序列表作为一个集合,但是如何在编译时设置该集合将要保存的元素或对象的类型?

hi all ,
I have taken sorted list as a collection but how can i set at compile time what type of elements or objects this collection is going to hold ?

推荐答案

通用版本,并指定类型或从SortedList派生您自己的类,并重写Add方法以仅接受特定类型.
You can either use the generic version and specify the type or derive your own class from SortedList and override the Add method to only accept a specific type.


Sortedlist具有一个键值对.该值可以是任何值,因此您可以在编译时进行设置.

除此之外,我不确定我是否能正确理解您的问题.
A Sortedlist has a Key value pair. The value can be anything so you can set this at compile time.

Other than than, I''m not sure I understand your question correctly.


这篇关于如何在编译时设置什么类型的对象集合保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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