Error in ToString method ("C3") [closed]

-2

I did this in the constructor of my class and now it gives error saying that there is no overhead for the ToString method with 1 argument. It was working, I cleaned the solution and it all went down.

Mapper.Initialize(cfg => {

                //string userName = null;
                cfg.CreateMap<LiberacaoDTO, Liberacao>()
                    .ForMember(d => d.Juros,
                        opt => opt.MapFrom(src => Juros.ToString("C3")
                        ));
            });
    
asked by anonymous 27.08.2017 / 19:29

2 answers

1

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

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

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

    
28.08.2017 / 00:28
0

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

public double? Juros { get; set; }

I took ? (nullable) and it worked.

    
27.08.2017 / 22:43