Skip to content

C# how can return value from class?

kris

Asked Mar 24, 2015, 2:23 AM EDT1 answer
Share
LinkedInX
I have class within class
 
C#
public class List
    {
        public int RecordCount { get; set; }
        public IEnumerable<ServiceElementItem> ServiceElement { get; set; }
    }

    public class ServiceElementItem
    {
        public int ServiceElementId { get; set; }
        public string ServiceElementBusinessId { get; set; }
        public string Description { get; set; }
        public string CustomerName { get; set; }
        public string SiteName { get; set; }
        public string Location { get; set; }

    }
 
And this should return back:
 
RecordCount: 1
ServiceElements:
[
1]
0:
{
ServiceElementId: 1
ServiceElementBusinessId: "TEST"
Description: "Direct"
AlternateId: "12345"
CustomerName: "TEST CUSTOMER"
SiteName: "TEST SITE"
}
 but it is returning back
RecordCount: 1
ServiceElements:null
 
How can i solve this in c# 

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Sudhansu Sekhar Prusty
    0
    You need to initialize certain values in your class constructor or in the returning  method.

    //Constructor

    public List()
    {
    this.RecordCount  = 1;

    this.ServiceElements = new 
     IEnumerable<ServiceElementItem>{{
    ServiceElementId: 1
    ServiceElementBusinessId: "TEST"
    Description: "Direct"
    AlternateId: "12345"
    CustomerName: "TEST CUSTOMER"
    SiteName: "TEST SITE"
    }};

    }
    0