| | |
Body-less method declaration
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2009
Posts: 3
Reputation:
Solved Threads: 0
Hello
I have seen the following method syntax and I am trying to understand how this works/or doesn't:
public class MyClass
{
public MyClass();
public MyClass(string param);
}
There is no implementation of the methods (constructors) and class is not declared virtual either...
Is this something new in C# 3.0 ???
Any ideas???
Thank you
I have seen the following method syntax and I am trying to understand how this works/or doesn't:
public class MyClass
{
public MyClass();
public MyClass(string param);
}
There is no implementation of the methods (constructors) and class is not declared virtual either...
Is this something new in C# 3.0 ???
Any ideas???
Thank you
0
#2 Oct 23rd, 2009
That doesn't compile in 3.5 and I think the error message answers your question:
Interfaces allow you to declare methods similarly but the method must have a return type:
I suspect you were looking at partial class definitions.
text Syntax (Toggle Plain Text)
'daniweb.MyClass.MyClass()' must declare a body because it is not marked abstract, extern, or partial 'daniweb.MyClass.MyClass(string)' must declare a body because it is not marked abstract, extern, or partial
Interfaces allow you to declare methods similarly but the method must have a return type:
C# Syntax (Toggle Plain Text)
public interface ITest { void ITest(); }
I suspect you were looking at partial class definitions.
0
#4 Oct 23rd, 2009
You can't have abstract constructors since the child classes cannot implement constructors from an inherited class...
None of these are valid:
None of these are valid:
C# Syntax (Toggle Plain Text)
public abstract class AbstractClass { abstract AbstractClass(); } public abstract class AbstractClass2 { AbstractClass2(); } public class AbstractClass3 { abstract AbstractClass3(); }
•
•
Join Date: Jul 2009
Posts: 903
Reputation:
Solved Threads: 144
•
•
•
•
Hello
I have seen the following method syntax and I am trying to understand how this works/or doesn't:
public class MyClass
{
public MyClass();
public MyClass(string param);
}
There is no implementation of the methods (constructors) and class is not declared virtual either...
Is this something new in C# 3.0 ???
Any ideas???
Thank you
Last edited by DdoubleD; Oct 24th, 2009 at 9:33 am.
![]() |
Similar Threads
- missing return statement (Java)
- abstract and interfaces (C#)
- virtual void method() = 0; problem (C++)
- setAttribute and IE7 (JavaScript / DHTML / AJAX)
- how is abstact class different from Interface?? (Java)
- Seven Parallel Vectors (Java)
- Problems with overload operator method (C++)
- Method problems (Java)
- Fibonacci Recursion - Illegal Start of expression! (Java)
- Combined data type arrays. (C++)
Other Threads in the C# Forum
- Previous Thread: Mouse Pointer moves on specified location dynamically
- Next Thread: DataReader clean up
| Thread Tools | Search this Thread |
.net access ado.net algorithm array barchart bitmap box broadcast buttons c# check checkbox client combobox connection console control conversion csharp custom database datagrid datagridview dataset datetime degrees deployment developer development draganddrop drawing editing encryption enum event excel file form format forms function gdi+ hospitalmanagementinformationsystem httpwebrequest image imageprocessing index input install java label list listbox mandelbrot math mouseclick mysql operator oracle path photoshop picturebox pixelinversion post priviallages. programming radians regex remote remoting richtextbox rows serialization server sleep socket sql statistics stream string table temperature text textbox thread time timer txt update uploadatextfile usercontrol validation visualstudio webbrowser windows windowsformsapplication winforms wpf xml






