在C#中哪个类别做结肠" :"陷入,它有什么究竟意味着什么? [英] In C# what category does the colon " : " fall into, and what does it really mean?

查看:124
本文介绍了在C#中哪个类别做结肠" :"陷入,它有什么究竟意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图获得有关微软开发人员网站引用什么​​的功能:其实这不过是因为它似乎既不是一个关键字或经营者我不能找到它究竟什么是结肠的功能C#?此外,我已经看到它被应用到方法如何实现该功能?

I have been trying to get reference in the Microsoft Developer website about what the function of the : really is but I cant find it because it seems that it is neither a keyword or a operator so what is the function of the colon in C#? Also I have seen it being applied to a Method how does that function?.

推荐答案

冒号在七个根本不同的地方使用(即我能想到的,每个人都在评论的帮助下):

Colons are used in seven fundamentally different places (that I can think of, with the help of everyone in the comments):


  • 在类定义或通用约束定义从基类/接口实现分离的类名称

  • Separating a class name from its base class / interface implementations in class definitions or in generic constraint definitions

public class Foo : Bar { }

public class Foo<T> where T : Bar { }

public void Foo<T>() where T : Bar { }


  • 指示如何调用之前对当前类的另一个构造函数或基类的构造函数为当前构造

  • Indicating how to call another constructor on the current class or a base class's constructor prior to the current constructor

    public Foo() : base() { }
    
    public Foo(int bar) : this() { }
    


  • 指定的全局命名空间(如℃。郎的指出,这是的命名空间别名限定符

    global::System.Console
    


  • 指定目标的属性。

  • Specifying attribute targets

    [assembly: AssemblyVersion("1.0.0.0")]
    


  • 指定参数名称

  • Specifying parameter names

    Console.WriteLine(value: "Foo");
    


  • 作为三元前pression的一部分

  • As part of a ternary expression

    var result = foo ? bar : baz;
    


  • 作为案例的一部分转到标签

    switch(foo) { case bar: break; }
    
    goto Bar;
    Foo: return true;
    Bar: return false;
    


  • 在所有这些情况下,结肠不被用作操作员或关键字(与除外:: )。它分为简单的语法符号的范畴,如 [] {} 。他们只是为了让编译器知道正是他们身边的其他符号的含义。

    In all these cases, the colon is not used as an operator or a keyword (with the exception of ::). It falls into the category of simple syntactic symbols, like [] or {}. They are just there to let the compiler know exactly what the other symbols around them mean.

    这篇关于在C#中哪个类别做结肠&QUOT; :&QUOT;陷入,它有什么究竟意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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