C# 不使用类名就可以实现C构造函数吗?

C# 不使用类名就可以实现C构造函数吗?,c#,constructor,C#,Constructor,在查看分解的.NET程序集时,我注意到构造函数被定义为.ctor。在实际代码中可以这样做吗?当然可以,如果你是用C写的,而不是用C写的。这只是C和IL之间的语法差异。在C代码中定义构造函数时,需要调用类名。你想要完成什么?不明白你为什么想要这个 您可以使用VS snippet构造函数,并获得一个免费的构造函数 只需键入ctor并按tab键两次。RE: 该死的。。。它更容易使用 在代码片段中 这是用于Visual Studio代码段的吗?它们已经有一个名为ctor的类来代替类名。如果它的默认行为不

在查看分解的.NET程序集时,我注意到构造函数被定义为.ctor。在实际代码中可以这样做吗?

当然可以,如果你是用C写的,而不是用C写的。

这只是C和IL之间的语法差异。在C代码中定义构造函数时,需要调用类名。你想要完成什么?

不明白你为什么想要这个

您可以使用VS snippet构造函数,并获得一个免费的构造函数

只需键入ctor并按tab键两次。

RE:

该死的。。。它更容易使用 在代码片段中

这是用于Visual Studio代码段的吗?它们已经有一个名为ctor的类来代替类名。如果它的默认行为不是你想要的,你可以看看它的定义

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>ctor</Title>
            <Shortcut>ctor</Shortcut>
            <Description>Code snippet for constructor</Description>
            <Author>Microsoft Corporation</Author>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
            </SnippetTypes>
        </Header>
        <Snippet>
            <Declarations>
                <Literal Editable="false">
                    <ID>classname</ID>
                    <ToolTip>Class name</ToolTip>
                    <Function>ClassName()</Function>
                    <Default>ClassNamePlaceholder</Default>
                </Literal>
            </Declarations>
            <Code Language="csharp"><![CDATA[public $classname$ ()
    {
        $end$
    }]]>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>

不必麻烦键入类名或回答?两件事都不能说我同意。