Static does not share values between web users

Asked

Viewed 49 times

2

It is possible to use a property static without sharing values between different users?

Sort of like Session?

Ex: of the scenario:

private static double valorRetorno;

public CalculaValor()
{
 valorRetorno = //recupera valor do cliente
}

public Imprimi()
{
 Imprimi(valorRetorno); //algo do tipo
}

// logic

Cliente 01 passa pela etapa CalculaValor()
Cliente 01 = valor 25,00
Cliente 01 vai para o setor de Imprimir()
Cliente 02 - entra no Calcular Valor
Cliente 02 = valor 30,00

Cliente 01 - acaba imprimindo o valor 30,00

OBS: If I just remove the property static the print will have the valorRetorno as zero.

  • 3

    If you want something "more or less like Session", why not use Session?

  • Why static?

1 answer

2


It is not possible, the static just indicates a sharing of the data across the application. With this modifier the member becomes unique to the class and all instances access it.

I do not know if I understood what you want but the solution in this case seems to be to keep the member as part of the instance. Maybe it should be used differently, only with what is in the question can not know the correct form of use. And I don’t know if it’s important to the problem.

I won’t comment on the fact that using a monetary value as double.

  • 1

    was an example, would use decimal or something.. If it was not possible to create the instance inside the print, then you would not have Solution only a Session, but that from there is always string

Browser other questions tagged

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