Condition between ArrayChar and int number how to do?

RK3

New member
Joined
Aug 20, 2020
Messages
1
Programming Experience
Beginner
Hi;
I am not getting the condition to interpret char array with integer :

C#:
string AjusteICMSDocumentoId = "102345";

char[] array = entidade.AjusteICMSDocumentoId.ToCharArray();

if (array[1] == 0)
{
    if (viewModel.TipoImposto != (int)WorkDev.ERP.WApp.Core.Enums.FiscalEnum.TipoImpostoICMSAjusteEnum.ICMS)
    {
        await _notificacaoDominio.Adicionar(nameof(ICMSAjusteViewModel), string.Format(Criticas.Informacoes_Invalidas));
        return viewModel;
    }             
}
 
Last edited by a moderator:
That's because it is a char and not an int. Either compare char or convert to int:
array[1] == '0'
char.GetNumericValue(array[1]) == 0
Parsing the string is also possible, like one of these:
int.Parse(array[1].ToString()) == 0
int.Parse(AjusteICMSDocumentoId.Substring(1,1)) == 0
 
As a quick aside there is no need to convert the string to a char array. So instead of
C#:
char[] array = entidade.AjusteICMSDocumentoId.ToCharArray();

if (array[1] == '0')
you could just do
C#:
if (entidade.AjusteICMSDocumentoId[1] == '0')
 

Latest posts

Back
Top Bottom