任何人都可以解释'object [] m_Items'和'string [] names'之间的区别 [英] Anyone can explain difference between 'object[] m_Items' and 'string[] names'

查看:150
本文介绍了任何人都可以解释'object [] m_Items'和'string [] names'之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好..



任何人都可以解释之间的区别

  object  [] m_Items = {  Tom,< span class =code-string>  Mitch  Steve}; 









  string  [] names = {   Tom  Mitch  Steve}; 

解决方案

进入sting []名称,你只能添加字符串。



进入对象[] m_items你可以做任何事情。但这不是类型安全的。如果你使用string [],你知道每个内容元素都是一个字符串。但是对象[]你不知道你得到了什么。



也许看看类型安全。


< blockquote>

 object [] m_Items = {Tom,Mitch,Steve}; 





m_Items由对象引用组成。字符串(Tom,Mitch和Steve)存储为其基本类型。另一方面



 string [] names = {Tom,Mitch,Steve}; 





names是一个字符串数组,数组是强类型的。



当你你需要访问m_Items的对象.ToString()它们来获取真正的字符串引用(或至少转换它),但在后一种情况下,数组中的引用已经是类型字符串。



请告诉我这是否清楚,或者您是否正在寻找更具体的CLR?


您可以添加任何对象[]项目对象类型,

例如:

object [] items = {abc,0,123,dskfjakl}。

haven'没试过


hello everyone..

Anyone can explain difference between

object[] m_Items = { "Tom", "Mitch", "Steve" };



And

string[] names = { "Tom", "Mitch", "Steve" };

解决方案

Into sting[] names you can add strings only.

Into object[] m_items you can do everything. But this is not type safe. If you work with string[] you know that every content element is a string. But with object[] you don''t know what you get.

Maybe take a look a "Type safety".


object[] m_Items = { "Tom", "Mitch", "Steve" };



m_Items is composed of object references. The strings (Tom, Mitch and Steve) are stored as their base types. On the other hand

string[] names = { "Tom", "Mitch", "Steve" };



names is an array of strings, and the array is strongly typed.

When you access objects of of m_Items you would have to .ToString() them to get the real string reference (or atleast cast it), But in the later case the references in the array are already of type strings.

Please let me know if this was clear or are you looking for something even more specific to the CLR?


The object[] items you can add any type of object,
for example:
object[] items={"abc",0,123,"dskfjakl"}.
haven''t tried


这篇关于任何人都可以解释'object [] m_Items'和'string [] names'之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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