Tostring("C3") error

Asked

Viewed 513 times

-2

I did this in the constructor of my class and now gives error saying that there is no overload for the Tostring method with 1 argument. It was working, I gave a clean in the Solution and it broke everything.

Mapper.Initialize(cfg => {

                //string userName = null;
                cfg.CreateMap<LiberacaoDTO, Liberacao>()
                    .ForMember(d => d.Juros,
                        opt => opt.MapFrom(src => Juros.ToString("C3")
                        ));
            });
  • Your Property Interest is Nullable<float>?

  • What kind of property Interest?

  • double? But it was working, so I gave a clean on Solution and it didn’t work anymore

  • I removed the null(double) and gave no more error.

  • What it is to give a Clean on the Solution?

2 answers

1

The point is that Nullable inherits directly from the class object, and Object does not have a Tostring() that accepts a string. To make use of Tostring() with a parameter that accepts formatting you would have to use:

opt.MapFrom(src => Juros.Value.ToString("C3")

For when I call the estate Value of Nullable, it gives me the primitive decimal that inherits directly from the class ValueType, that has its Tostring(string format). It is still worth mentioning that my example will give an exception if my Interest is null. Validate the null.

0

The question was as follows. It gave the error, because the field was set as Nullable<double>, thus:

public double? Juros { get; set; }

I took the ?(nullable) and it worked.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.