set in model class is not functionnal!

sblb 1,231 Reputation points
2022-08-18T16:41:54.957+00:00

Hi, I have the class model below and when the condition DTb is verified Statut take the "Open".
When the Status of the DTb changes my app is blocked. Is not possible to use dev tool because the application is blocked.

public string CloseOn { get; private set; }  
        public string Statut  
        {  
              
         get  
           {  
              if (DTb != "Validated")  
                  {  
                      string var1;  
                       var1 = "Open";  
                      return var1;  
                 }  
               return Statut;  
            }  
         set  
            {                  
                   if (DTb == "Validated")  
                   {  
                     CloseOn = "Closed";  
                   }  
                  
            }  
                 
        }  

Is the model class I wrote correct?
Have you an idea why my application is blocked ?
Thanks in advance

Developer technologies .NET Blazor
Developer technologies C#
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 122.5K Reputation points
    2022-08-18T16:47:01.66+00:00

    I think that the 'return Statut' calls Statut again and again (infinitely or until an overflow error). This blocks your application.

    You should return something else. (Maybe 'return CloseOn'?).


1 additional answer

Sort by: Most helpful
  1. AgaveJoe 30,126 Reputation points
    2022-08-18T20:21:15.017+00:00

    You have to understand the code you've shared is nonsensical. Therefore, the community is unable to infer your intent from the code. Please explain the use case and perhaps the community can provide a logical approach.

    The C# programming guide has a section on properties which might prove helpful.

    Properties (C# Programming Guide)

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.