什么是内/地方/匿名类的条款Java和C#之间的根本区别是什么? [英] What are the fundamental differences between Java and C# in terms of inner/local/anonymous classes?

查看:134
本文介绍了什么是内/地方/匿名类的条款Java和C#之间的根本区别是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是的内/地方/匿名类的条款Java和C#之间的根本区别

推荐答案

C#不具备的Java内部类的等价物 - 它只有嵌套类型(如Java的静态嵌套类。)

C# doesn't have the equivalent of Java inner classes - it only has nested types (like Java's "static" nested classes).

访问规则稍有不同 - 在Java中,外部类访问其嵌套类的私有成员,反之亦然。在C#的嵌套类可以访问外部类的私有成员,但的的其他方式轮。

The access rules are slightly different - in Java, an outer class has access to its nested class's private members, and vice versa. In C# the nested class has access to the outer class's private members, but not the other way round.

C#不具有匿名内部类如Java,但它的确实的有匿名方法和lambda表达式,这是实现的的什么匿名内部类通常用于更清洁的方式。这两个机制的变量捕捉是不同的 - 见我闭包文章更多细节。

C# doesn't have anonymous inner classes like Java, but it does have anonymous methods and lambda expressions, which are a much cleaner way of achieving most of what anonymous inner classes are usually used for. The variable capture for the two mechanisms is different - see my article on closures for more details.

这篇关于什么是内/地方/匿名类的条款Java和C#之间的根本区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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