When I write the code below I'm getting the error: "must declare a body because it is not marked abstract or extern" for get and set accesors. What am I doing wrong?
The problem is that you declared no body for the get and set.
using System;
namespace Dados
{
public abstract class Manutencao : IDados
{
public Manutencao() { }
public abstract string Nome { get; set; }
public abstract string Idade { get; set; }
}
}
Thanks a lot nberardi for reply and sorry for my newbie question but why did you add abstract keyword and what would be the content of that IDados interface that is being inheritanced?
Hey no problem we all have to learn. Basically an interface is just that just a set of properties and methods that tell you how to access a class. So they naturally come with no code. However when you impliment an interface you also have to impliment the
code to define that interface. For example:
using System;
namespace Dados
{
public class Manutencao : IDados
{
private string _nome;
private string _idade;
public Manutencao() { }
public string Nome
{
get { return _nome; }
set { _nome = value; }
}
public string Idade
{
get { return _idade; }
set { _idade = value; }
}
}
}
just my 2 cents if anyone is looking at this. If you are using Visual Studio 2008, You can target your compiler to compile at 3.5 framework which supports Automatic Properties. If you are using 2.0 then you will need to have abstract class interface.
just my 2 cents if anyone is looking at this. If you are using Visual Studio 2008, You can target your compiler to compile at 3.5 framework which supports Automatic Properties. If you are using 2.0 then you will need to have abstract class interface.
This is incorrect. Automatic properties are a function of the compiler, not of the framework you're targeting. VS2k8 will still work with automatic properties when targeting the .Net 2.0 runtime. However VS2k5 will not give you automatic properties.
If the answer I provided is useful or informative please check the "answer" button.
Warning: Code is often uncompiled and possibly started life written on the back of a napkin. Beware typos.
There is nothing wrong with the code you have posted, so far. I supsect that the interface IDados has some other members declared that need to be implemented in your Manutencao class. The easy way to get them implemented is to position your cursor on IDados
(in this file, not in the declaration of IDados) and press Alt-Shift-F10 and then Enter. This will give default implementations for any parts of the interface which have not been implemented in your concrete class.
Error is not because of wrong code but its because of missing code. I think Interface IDados will be having few methods which has not been implemented in the class. Once you do that the error will vanish. :)
You are apparently trying to compile C# version 3.0 code (which is supported by Visual Studio 2008) with a C# version 2.0 compiler (which is what is included in Visual Studio 2005).
For your compiler, you'll have to write:
private string _nome;
public string Nome
{
get { return _nome; }
set { _nome = value; }
}
private string _idade;
public string Idade
{
get { return _idade; }
set { _idade= value; }
}
More to write - but the same code is actually produced in the end.
To ease the burden of your fingers, try typing 'prop' <TAB><TAB> when you want to insert a property like this. <TAB> represents a single press on the tabulator key, usually identified with a right and left arrow, usually placed at the left edge of the keyboard.
Svante
AxCrypt - Free Open Source File Encryption & Online Password Manager - http://www.axantum.com [Disclaimer: Code snippets usually uncompiled, beware typos.]
______
Don't forget to click "Mark as Answer" on the post(s) that helped you.
You are apparently trying to compile C# version 3.0 code (which is supported by Visual Studio 2008) with a C# version 2.0 compiler (which is what is included in Visual Studio 2005).
For your compiler, you'll have to write:
private string _nome;
public string Nome
{
get { return _nome; }
set { _nome = value; }
}
private string _idade;
public string Idade
{
get { return _idade; }
set { _idade= value; }
}
More to write - but the same code is actually produced in the end.
To ease the burden of your fingers, try typing 'prop' <TAB><TAB> when you want to insert a property like this. <TAB> represents a single press on the tabulator key, usually identified with a right and left arrow, usually placed at the left edge of the keyboard.
Roberot
Participant
1051 Points
416 Posts
must declare a body because it is not marked abstract or extern
Oct 03, 2006 12:07 PM|LINK
When I write the code below I'm getting the error: "must declare a body because it is not marked abstract or extern" for get and set accesors. What am I doing wrong?
Thanks a lot
using System;
namespace Dados{
public class Manutencao : IDados
{
public Manutencao()
{ }
public string Nome { get; set;}
public string Idade { get; set;}
}
}
Ivan Andrade
nberardi
Star
11233 Points
2352 Posts
Re: must declare a body because it is not marked abstract or extern
Oct 03, 2006 02:16 PM|LINK
using System; namespace Dados { public abstract class Manutencao : IDados { public Manutencao() { } public abstract string Nome { get; set; } public abstract string Idade { get; set; } } }Roberot
Participant
1051 Points
416 Posts
Re: must declare a body because it is not marked abstract or extern
Oct 03, 2006 02:35 PM|LINK
Ivan Andrade
nberardi
Star
11233 Points
2352 Posts
Re: must declare a body because it is not marked abstract or extern
Oct 03, 2006 02:46 PM|LINK
using System; namespace Dados { public class Manutencao : IDados { private string _nome; private string _idade; public Manutencao() { } public string Nome { get { return _nome; } set { _nome = value; } } public string Idade { get { return _idade; } set { _idade = value; } } } }zamankazi
Member
8 Points
4 Posts
Re: must declare a body because it is not marked abstract or extern
Mar 19, 2009 03:43 PM|LINK
JeffreyABeck...
All-Star
16423 Points
3329 Posts
Re: must declare a body because it is not marked abstract or extern
Mar 19, 2009 08:31 PM|LINK
Warning: Code is often uncompiled and possibly started life written on the back of a napkin. Beware typos.
Paul Linton
Star
13431 Points
2535 Posts
Re: must declare a body because it is not marked abstract or extern
Mar 21, 2009 11:17 PM|LINK
There is nothing wrong with the code you have posted, so far. I supsect that the interface IDados has some other members declared that need to be implemented in your Manutencao class. The easy way to get them implemented is to position your cursor on IDados (in this file, not in the declaration of IDados) and press Alt-Shift-F10 and then Enter. This will give default implementations for any parts of the interface which have not been implemented in your concrete class.
fundu.ujjwal
Member
365 Points
102 Posts
Re: must declare a body because it is not marked abstract or extern
Mar 31, 2009 08:41 PM|LINK
Ujjwal ;)
More I learn I know, how less I know..
Svante
All-Star
18347 Points
2300 Posts
Re: must declare a body because it is not marked abstract or extern
Apr 01, 2009 07:09 AM|LINK
You are apparently trying to compile C# version 3.0 code (which is supported by Visual Studio 2008) with a C# version 2.0 compiler (which is what is included in Visual Studio 2005).
For your compiler, you'll have to write:
private string _nome; public string Nome { get { return _nome; } set { _nome = value; } } private string _idade; public string Idade { get { return _idade; } set { _idade= value; } }More to write - but the same code is actually produced in the end.
To ease the burden of your fingers, try typing 'prop' <TAB><TAB> when you want to insert a property like this. <TAB> represents a single press on the tabulator key, usually identified with a right and left arrow, usually placed at the left edge of the keyboard.
AxCrypt - Free Open Source File Encryption & Online Password Manager - http://www.axantum.com
[Disclaimer: Code snippets usually uncompiled, beware typos.]
______
Don't forget to click "Mark as Answer" on the post(s) that helped you.
ddredstar@ho...
Member
351 Points
116 Posts
Re: must declare a body because it is not marked abstract or extern
Apr 01, 2009 07:22 AM|LINK
Absolutely agree with u!!!