Click here to Skip to main content
15,921,793 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to assign data to below List with class object in c#.
List<remittancedatum> is the list I want to assign.

My Model class is as below:
 public class Data
        {
            public List<RemittanceDatum> RemittanceData { get; set; }
            public string PaymentOrderProductId { get; set; }
            public string DebitAccountId { get; set; }
            public string DebitCurrency { get; set; }
            public string DebitValueDate { get; set; }
            public string CreditAccountId { get; set; }
            public string PaymentCurrencyId { get; set; }
            public int Amount { get; set; }
            public string EndToEndReference { get; set; }
        }

        public class RemittanceDatum
        {
            public string Information { get; set; }
        }

What I have tried:

My code is as below:
<pre>List<RemittanceDatum> RemittanceDatum = new List<RemittanceDatum>();
                            RemittanceDatum data = new RemittanceDatum();
                            data.Information = "JOhn";
                            RemittanceDatum.Add(data);



I have converted a json string to c# object
json string
JavaScript
{
"Data": {
"RemittanceData": [
{
"Information": "TEST503"
}
],
"PaymentOrderProductId": "AHBDDA503",
"DebitAccountId": "30000138149",
"DebitCurrency": "AED",
"DebitValueDate": "20220307",
"CreditAccountId": "30000904151",
"PaymentCurrencyId": "AED",
"Amount": 1,
"EndToEndReference": "TEST503PAYMENT"
}
}


class file
C#
public class DDS_TRANSACT_POSTING_REQUEST_DETAILS
  {
      public class Data
      {
          public List<remittancedatum> RemittanceData { get; set; }
          public string PaymentOrderProductId { get; set; }
          public string DebitAccountId { get; set; }
          public string DebitCurrency { get; set; }
          public string DebitValueDate { get; set; }
          public string CreditAccountId { get; set; }
          public string PaymentCurrencyId { get; set; }
          public int Amount { get; set; }
          public string EndToEndReference { get; set; }
      }

      public class RemittanceDatum
      {
          public string Information { get; set; }
      }

      //public class Root
      //{
      //    public Data Data { get; set; }
      //}



  }

I want to assign data to the information attribute in the List<remittancedataum> as John and then serialize the same to json string
Posted
Updated 26-Sep-22 6:20am
v2

1 solution

You are confusing the compiler:
C#
List<RemittanceDatum> RemittanceDatum = new List<RemittanceDatum>();

You have already defined RemittanceDatum as a class, so you need a different name for your list. But it is not clear exactly what you are trying to do.
 
Share this answer
 
Comments
Member 7513082 26-Sep-22 12:04pm    
Content moved to the original question.
Richard MacCutchan 26-Sep-22 12:22pm    
It is still not clear exactly what the problem is. Please use the Improve question link above, and add complete details of what is not working.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900