-2

Possible Duplicate:
'POCO' definition

i have simple class called books. It need to be converted into POCO class. What changes. need to be done?

class **BOOKS**
{
    private string authorName;
    public string *getName*
       {
          return authorName;
       }
    public string *setName*
       {
         authorName=value;
      }
}

non static class with 2 props.

Community
  • 1
  • 1
shaik
  • 21
  • 1
  • 2

4 Answers4

2

No changes - you're poco ready :-D

Ventsyslav Raikov
  • 6,882
  • 1
  • 25
  • 28
0
public class Book
{
    public string AuthorName { get; set; }
}
Jakub Konecki
  • 45,581
  • 7
  • 87
  • 126
  • Property must return List<>. Need to add Name and email for every author. How? static class testClass{ private static List _fname = new List(new string[] { "Madra", "Bangalore", "Hyderabad", "Bombay", "Trivandrum" }); public static List Fname { get { return _fname; } } } Is it POCO ready? If yes how to instantiate and call from any Main()? – shaik Jun 22 '12 at 13:47
0

Per biziclop's link, it probably already is a Plain Old C# Object. But to make it plainer, you could write it like this:

class BOOKS
{
    public string AuthorName { get; set; }
}

This feature is called Auto-Implemented properties, and was introduced with C# 3.0

McGarnagle
  • 101,349
  • 31
  • 229
  • 260
0

If your class doesn't include any third party attributes in your class.

Please check out the MSDN link about POCO.

http://msdn.microsoft.com/en-us/library/cc681329.aspx

In your above code, replace the two methods with a single property.

private string _authorName;
public string AuthorName
{
    get
    {
        return _authorName;
    }
    set
    {
        _authorName=value;
    }
}
Kishore Kumar
  • 12,675
  • 27
  • 97
  • 154
  • Property must return List<>. Need to add Name and email for every author. How? Can i use this code, static class testClass { private static List fname = new List(new string[] { "Madra", "Bangalore", "Hyderabad", "Bombay", "Trivandrum" }); public static List testProp { get { return fname; } } } Is it POCO ready? If yes how to instantiate and call from any Main()? – shaik Jun 22 '12 at 13:40