Reputation: 16325
When looking at disassembled .NET assemblies I notice that constructors are defined as ".ctor". Is that possible to do in the actual code?
Upvotes: 1
Views: 677
Reputation: 5113
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.
Upvotes: 3
Reputation: 453608
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">
<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>
Upvotes: 3
Reputation: 60942
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?
Upvotes: 2