tags:

views:

203

answers:

4

When looking at disassembled .NET assemblies I notice that constructors are defined as ".ctor". Is that possible to do in the actual code?

+5  A: 

Sure, if you write in IL not if you write in C# though.

Motti
Damn ... it is much easier to use that in code snippets
Nick Brooks
+2  A: 

This is only a syntactic difference between C# and IL. You need to call out the class name when defining the constructor in your C# code. What are you looking to accomplish?

Michael Petrotta
Can't really be bothered to do so ...
Nick Brooks
Can't be bothered to type the class name, or to answer? Can't say I'm with you on either one.
Michael Petrotta
+3  A: 

Dont see the point why you want this.

You can use the VS snippet ctor and you get a free constructor.

Just type ctor and press two times the tab-key.

Henri
+3  A: 

RE:

Damn ... it is much easier to use that in code snippets

Is this for Visual Studio code snippets? They already have one called ctor that substitutes the class name. You could look at the definition of that if its default behaviour is not what you want.

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"&gt;
    <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>
Martin Smith