简体   繁体   English

C#是C的超集吗?

[英]Is C# a superset of C?

Is C# a superset of C in anyway, like Objective-C or C++? C#无论如何都是C的超集,比如Objective-C或C ++? Is there a way to compile C online with constructs such compiler flags? 有没有办法用构造这样的编译器标志在线编译C?

总之,没有。

Not in any meaningful way. 没有任何有意义的方式。 It's inspired by C (among others), but they are quite fundamentally different languages. 它的灵感来自C(以及其他),但它们是完全不同的语言。

C# comes from the "c-like" family as far as syntax is concerned, but as far as architecture it feels more like Java (no pointers [OK, as pointed out below, you can use them, but most people don't know or care about that], arrays are bound checked, garbage collected memory, etc). 语法而言,C#来自“c-like”系列,但就架构而言,它更像是Java(没有指针[好吧,如下所述,你可以使用它们,但是大多数人都不知道或者关心那个],绑定数组,垃圾收集内存等)。

You can get much of that in C++, but not in the core. 您可以在C ++中获得大部分内容,但不能在内核中获得。

Let's put it like this: 我们这样说:

C and C# are similar like rm -rf . / CC#类似于rm -rf . / rm -rf . / and # rm -rf . / rm -rf . /# rm -rf . / # rm -rf . / are similar # rm -rf . /是相似的

In short, no C is not a subset of C#. 简而言之,没有C不是C#的子集。 The look of many control structures base on C. Like, for-loops, switches, while and so on. 许多控制结构的外观基于C.比如,for-loops,switch,while等等。 At the same time, C# forbids potentially dangerous constructs, like falling off a case in a switch when forgetting a break;, or putting an integer as an if condition where a boolean is expected. 同时,C#禁止具有潜在危险的构造,例如在忘记中断时从交换机中的情况下掉落;或者将整数作为if条件放置,其中布尔值是预期的。 The above quote means that C# and C can look very similar, but translate to vastly different results. 上面的引用意味着C#和C看起来非常相似,但转化为截然不同的结果。 Where C will not prevent you from removing everything from your partition, C# will protect you from doing this by mistake, figuratively spoken. C不会阻止你从你的分区中删除所有东西,C#会保护你不要错误地这样做,比喻说。

At another level, C allows you to type-cast pointers to integers, push those around, cast back and then access memory locations that are then stored in that pointer. 在另一个级别,C允许您键入指向整数的指针,推送它们,转回然后访问存储在该指针中的内存位置。 C will not protect you from accessing memory which isn't allocated by you. C不会保护您不会访问未分配的内存。 You will get a crash - at best. 你会崩溃 - 充其量。 C# - on the other side - will have exceptions that notice you when you do things like accessing object throgh a null-reference. 另一方面,C#会有例外情况,当您执行访问对象时会注意到引用空引用。

C ++也不是C的真正超集(参见链接文本

C# and C are not really related(aside from similar syntax). C#和C并没有真正相关(除了类似的语法)。 C# is jitted down to machine code from IL when the program starts. 程序启动时,C#会从IL中删除机器代码。 C# doesn't have pointers with the exception of value types on that stack. 除了该堆栈上的值类型之外,C#没有指针。 C# is fully type safe, C is not. C#是完全类型安全的,C不是。 C requires explicit memory management where as C# is garbage collected. C需要显式内存管理,因为C#是垃圾回收。 The list of differences goes on and on... 差异列表一直在继续......

C# is very different from C (and also C++ is very different from C). C#与C非常不同(C ++也与C非常不同)。 This not because the semanthics, which are at the end not too different, but because of the concepts, the ideas that are behind C#. 这不是因为semanthics,它们最终没有太大的不同,而是因为概念,C#背后的想法。

When you program in C# you have to think in a different way from what you are used to do if you use C: this is the main difference. 当你使用C#进行编程时,如果使用C,你必须采用与以往不同的方式进行思考 :这是主要区别。

C is imperative. C势在必行。 C# is object oriented. C#是面向对象的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM