Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert variable to constant

Can seems to be strange, but is there a way to declare or convert variable to constante something like :

string myVariable = "MyString";
const string myConstant = myVariable ;

I need this to answer to my problem: linq to sql startwith performance indexed columns

thanks

like image 707
Julian50 Avatar asked Jan 09 '23 18:01

Julian50


1 Answers

no there is no way to do this for Const Const values are burned directly into the call-site at compile time, Instead you could make it readonly and assign it in the constructor

something like

string myVariable = "MyString";
readonly  string myConstant="test" ; 
public MyClass()
{ 
myConstant= myVariable ;
}
like image 172
BRAHIM Kamel Avatar answered Jan 19 '23 13:01

BRAHIM Kamel