C#:非零基于阵列是不符合CLS [英] C#: Nonzero-based arrays are not CLS-compliant

查看:195
本文介绍了C#:非零基于阵列是不符合CLS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在读的阿尔巴哈利的的 C#3.0中果壳和皮克。 241,而谈论的数组索引,他这样说:

I am currently reading Albahari's C# 3.0 in a Nutshell and on pg. 241, whilst talking about Array indexing, he says this:

非零基于阵列不
  CLS(通用语言规范)标准

Nonzero-based arrays are not CLS (Common Language Specification)-compliant

这是什么意思完全相同,为非零阵列不是符合CLS ?而且它有什么影响你的code?

What does it mean exactly, for nonzero arrays to not be CLS compliant ? And what implications does it have on your code?

[更新]

<一个href=\"http://books.google.com.mt/books?id=%5FY0rWd-Q2xkC&pg=PA241&lpg=PA241&dq=c%23%2B3.0%2Bin%2Ba%2Bnutshell%2BNonzero-based%2Barrays%2Bare%2Bnot%2BCLS%2B%28Common%2BLanguage%2BSpecification%29-compliant&source=bl&ots=R7ExO7UHWh&sig=OxLJ0tc3gByD8tsI3b394u%5F9aks&hl=mt&ei=HjQpSoiwEITG-AamuenqCA&sa=X&oi=book%5Fresult&ct=result&resnum=2\">Here是书的页面的链接。

推荐答案

的CLS(公共语言规范)奠定了遵守一套共同的规则,保证了基础,其他语言(VB.NET,F#等)可以使用您已经用C#内置组件。其他语言期望数组是从零开始的基于非零阵不会是兼容的。

The CLS (Common Language Specification) lays the groundwork for a common set of rules for compliance that guarantees that other languages (VB.NET, F#, etc.) can use assemblies that you have built with C#. A nonzero-based array would not be compliant as other languages expect arrays to be zero-based.

下面是一个更容易的例子就明白了:

Here is an example that is easier to understand:

class Foo
{
    public void Bar() { }
    public void bar() { } 
}

本型会的的是CLS兼容,因为它包含了只有类型名称有所不同,两个成员。怎么会有人用VB.NET 酒吧间的歧义,因为VB.NET编译器是不区分大小写?

This type would not be CLS compliant since it contains two members that differ in name only by type. How would someone using VB.NET disambiguate between Bar and bar since the VB.NET compiler is not case-sensitive?

所以基本上是CLS一堆这样的规则,以保证语言之间的互操作性。

So basically the CLS is a bunch of rules like this to guarantee interoperability between languages.

这篇关于C#:非零基于阵列是不符合CLS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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