I have declared a constant variable which is being stored in cookie so its Ok because differnt browser will have a different copy.
private const string CookieName = "TempData";
Now I want to store it at third location where all user data will be stored.
So How can I declare something like
private const string CookieName = "TempData" + DataTime.Now.Tick.tostring(); So that each user will have differnet cookiename stored at third location.
Please advise.
For that you cannot use a const field. Anything with const modifier must be able to be evaluated to a constant at compile time.
What you want is a static field initialised by a static constructor
public class YourSurroundingClass {
private static readonly string CookieName;
static YourSurroundingClass() {
CookieName = "TempData" + DateTime.Now.Ticks
.ToString();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With