Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# convert viewstate to bool array

Tags:

arrays

c#

How I can convet viewstate to bool array

private bool[] clientCollapse
{
    get { return Convert.ToBoolean(ViewState["Collapse"]); }
    set { ViewState["Collapse"] = value; }
}

Any ideas???

like image 436
Harold Sota Avatar asked May 03 '26 09:05

Harold Sota


2 Answers

private bool[] clientCollapse
{
    get { return (bool[])ViewState["Collapse"]; }
    set { ViewState["Collapse"] = value; }
}

if will work if you set those values only using this propery, otherwise you can but there other type and cast will not work

BTW common naming convention for C# requires property names to start with capital: ClientCollapse

like image 92
Andrey Avatar answered May 05 '26 22:05

Andrey


You can do this:

private bool[] clientCollapse
{
    get { return (bool[])ViewState["Collapse"] ?? new bool[0]; }
    set { ViewState["Collapse"] = value; }
}
like image 32
Mr. TA Avatar answered May 05 '26 23:05

Mr. TA