i have a class where i am assigning currency variable as follows:
example currency formats USD,EUR etc etc
public class codes{
public char currency{get;set;}
}
so i have another class that calls codes to assign it into the currency variable as follows:
public async Task<Codes> ExecuteAsync(hCommand command){
Codes c = new Codes();
//i do some coding to get the currency back then i assign it as follows from a string
c.currency = Convert.ToChar(currency);
}
but it throws an error at that line System.FormatException: 'String must be exactly one character long.' and the output is returned as "currency": "\u0000"
how can i get it to be a char(3)
stringinstead ofcharpublic string currency { get; set; }? since you want value like USD or EURcurrencyvariable comming from? What is it set to? Why is it a string, if you plan to assign it to a char? Why not use a Enumeration?char(3)as you call it. You can usestring, or you can create your own typeCurrencythat holds a string which is assured to have the right format (like, not too long).