为什么没有数组类有costructor(为什么不是通过创造新的例如INT []()) [英] Why doesn't array class have a costructor (Why is it not created via e.g. new int[]())

查看:112
本文介绍了为什么没有数组类有costructor(为什么不是通过创造新的例如INT []())的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解他们的创作的语法如何在C#中的工作和阵列只是磁带和方括号(如新INT [] ),后面可以特殊括号与新阵列是项充满

I understand how arrays in C# work and that the syntax for their creation is just the tape and square parentheses (e.g. new int[]), optionally followed by special braces with the items that the new array is to be filled with.

该数组是,但是,一个内部(好吧,也许不是那么)正常类。并为一个它肯定有一个隐式的构造函数(不一定)创建一个阵列时,应对其调用应被语法体现 - >创作应该是新INT []()而不是它是什么......

The array is, however, internally a (ok, probably not so) normal class. And as one it surely has an implicit constructor (not necessarily) which should be invoked when an array is created which should be reflected by the syntax -> creation should be new int[]() instead of what it is...

但它显然不是这样的,我的问题是,为什么......是什么导致他们这样做,这(直观的)的方式...

But it obviously isn't like that and my question is why... what led them to do that this (unintuitive) way...

推荐答案

数组是非常不同的形式的简单类或者其他数据结构。与阵列的存储器分配和项目的访问是由CLR和/或编译器直接完成。
与其他数据结构,这是通过该数据结构code handeled

An array is very different form a simple class or other data structures. With an array the memory allocation and access of items is done directly by the CLR and/or the compiler. With other data structures this is handeled by the data-structure code.

因此​​,对于分配一定大小需要某些语法,让编译器做的工作的阵列。 VAR ARR =新INT [5]

So for allocating an array of a certain size some syntax is needed which let the compiler do the job. var arr = new int[5]

而不是它调用一个数据结构的构造就像一个语法
  VAR名单=新名单,LT; INT>(5)

instead of a syntax which calls a data-structure's constructor like var list = new List<int>(5)

这篇关于为什么没有数组类有costructor(为什么不是通过创造新的例如INT []())的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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