mardi 11 juillet 2023

Override ToString for pipe delimited file with the column headers in the first row

I have the following viewmodel which I am trying to create Pipe delimited string.
     public class CustomerViewModel
     {

          public string VendorCode { get; set; }


          public string MasterVendor { get; set; }


          public string ScorecardVendor { get; set; }


          public char? ImportOrDomestic { get; set; }
              
          public bool IsI2Of5Vendor { get; set; }

  This is What I have tried :

          public override string ToString()
          {

       string result = "|";

       return $"VendorCode {result} MasterVendor {result}  ScorecardVendor {result} ImportOrDomestic {result} IsI2Of5Vendor \n {VendorCode} {result} {MasterVendor}{result} {ScorecardVendor} {result} {ImportOrDomestic} {result} {IsI2Of5Vendor}";
}

Issue and expected output : With the above ToString(), I am getting column headers and values in single line, but I need VendorCode| MasterVendor|ScoreCardVendor in firstrow and then in second row its respective column values like 23|ALAN|PLASTICS.

Please suggest any solutions.





Aucun commentaire:

Enregistrer un commentaire