Click here to Skip to main content
15,887,746 members
Home / Discussions / C#
   

C#

 
AnswerRe: Desktop App or Access 2003? Pin
Paul Conrad14-Nov-08 8:48
professionalPaul Conrad14-Nov-08 8:48 
GeneralRe: Desktop App or Access 2003? Pin
hellbentuk15-Nov-08 1:41
hellbentuk15-Nov-08 1:41 
QuestionException Constructor Pin
George_George14-Nov-08 2:17
George_George14-Nov-08 2:17 
AnswerRe: Exception Constructor Pin
J4amieC14-Nov-08 2:23
J4amieC14-Nov-08 2:23 
GeneralRe: Exception Constructor Pin
George_George16-Nov-08 2:05
George_George16-Nov-08 2:05 
AnswerRe: Exception Constructor Pin
Le centriste14-Nov-08 5:44
Le centriste14-Nov-08 5:44 
GeneralRe: Exception Constructor Pin
George_George16-Nov-08 2:07
George_George16-Nov-08 2:07 
GeneralRe: Exception Constructor Pin
Le centriste16-Nov-08 2:33
Le centriste16-Nov-08 2:33 
All public and protected methods are inherited, except the constructors.

Suppose the following:

public class A
{
    public A()
    {
    }
}

public class B : A
{
    public B(int i)
    {
    }
}

A a = new A(); // Compiles OK
B b1 = new B(5); // Compiles OK
B b2 = new B(); // Compile error: No overload for method 'B' takes '0' arguments


If B does not define an empty constructor, it does not inherit it. There is one subtle thing happening here the compile does not tell you. Since B's only constructor does not specify which base class constructor to call, it calls A's empty costructor silently.

Consider the following code:

public class A
{
    public A(string s)
    {
    }
}

public class B : A
{
    public B(int i)
    {
    }
}

B b = new B(5); // Compile error: No overload for method 'A' takes '0' arguments


Since B does not specify which constructor from A to call, the compiler tries to place a call to A's empty constructor, but it does not exists, hence the error.

The following code would work:

public class A
{
    public A(string s)
    {
    }
}

public class B : A
{
    public B(int i) : base(i.ToString())
    {
    }
}

B b = new B(5); // Compiles OK


So, in your case, the base class defines a constructor for serialization, but you class does not inherit it.
GeneralRe: Exception Constructor Pin
George_George16-Nov-08 2:47
George_George16-Nov-08 2:47 
GeneralRe: Exception Constructor Pin
Le centriste16-Nov-08 2:54
Le centriste16-Nov-08 2:54 
GeneralRe: Exception Constructor Pin
George_George16-Nov-08 2:56
George_George16-Nov-08 2:56 
GeneralRe: Exception Constructor Pin
N a v a n e e t h17-Nov-08 15:06
N a v a n e e t h17-Nov-08 15:06 
GeneralRe: Exception Constructor Pin
George_George18-Nov-08 2:21
George_George18-Nov-08 2:21 
AnswerRe: Exception Constructor Pin
N a v a n e e t h14-Nov-08 17:36
N a v a n e e t h14-Nov-08 17:36 
GeneralRe: Exception Constructor Pin
George_George16-Nov-08 2:08
George_George16-Nov-08 2:08 
GeneralRe: Exception Constructor Pin
N a v a n e e t h16-Nov-08 3:35
N a v a n e e t h16-Nov-08 3:35 
GeneralRe: Exception Constructor Pin
George_George16-Nov-08 3:40
George_George16-Nov-08 3:40 
QuestionMediaElement Recorder Pin
mabbas_8614-Nov-08 2:09
mabbas_8614-Nov-08 2:09 
AnswerRe: MediaElement Recorder Pin
Thomas Stockwell14-Nov-08 2:55
professionalThomas Stockwell14-Nov-08 2:55 
Questionsimple example of asp.net page using control Pin
maifs14-Nov-08 1:58
maifs14-Nov-08 1:58 
AnswerRe: simple example of asp.net page using control Pin
Pr@teek B@h!14-Nov-08 3:01
Pr@teek B@h!14-Nov-08 3:01 
Questionsimple example of asp.net page using control Pin
maifs14-Nov-08 1:58
maifs14-Nov-08 1:58 
AnswerRe: simple example of asp.net page using control Pin
Vimalsoft(Pty) Ltd14-Nov-08 3:57
professionalVimalsoft(Pty) Ltd14-Nov-08 3:57 
GeneralRe: simple example of asp.net page using control Pin
Le centriste14-Nov-08 5:45
Le centriste14-Nov-08 5:45 
QuestionRun a screensaver from a C# .NET Framework 3.5 2008 Console Application Pin
Joshomedia14-Nov-08 0:02
Joshomedia14-Nov-08 0:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.