重复 "If statements" 保存并重复使用结果
Repetative "If statements" save and reuse results
我在 Visual Studio 视图中查看 MVC(razor 代码)。我在代码的不同区域多次使用相同的 bool "if statemant" 。有人告诉我,我可以保存第一个 if 语句的结果并重用结果,这样我就不必多次编写 "if statement"。
如何保存第一个 if 语句的结果并重复使用下面的结果?
var IsManager = someRole;
var IsTeamLead= someOtherRole;
if(IsManager || ITeamLead)
{
//Veiew this resticted content on the application;
}
//Code;
//Code;
if(IsManager || IsTeamLead)
{
//Veiew more resticted content on the application;
}
//Little more code;
//Little more Code;
if(IsManager || Is TeamLead)
{
//Veiew this content too;
}
//Little more code
//Little more code
//Little more code
if(IsManager || IsTeamLead)
{
//Veiew this content;
}
bool isManagerOrTeamLead = IsManager || ITeamLead;
然后...
if(isManagerOrTeamLead)
{
//Veiew this resticted content on the application;
}
我在 Visual Studio 视图中查看 MVC(razor 代码)。我在代码的不同区域多次使用相同的 bool "if statemant" 。有人告诉我,我可以保存第一个 if 语句的结果并重用结果,这样我就不必多次编写 "if statement"。
如何保存第一个 if 语句的结果并重复使用下面的结果?
var IsManager = someRole;
var IsTeamLead= someOtherRole;
if(IsManager || ITeamLead)
{
//Veiew this resticted content on the application;
}
//Code;
//Code;
if(IsManager || IsTeamLead)
{
//Veiew more resticted content on the application;
}
//Little more code;
//Little more Code;
if(IsManager || Is TeamLead)
{
//Veiew this content too;
}
//Little more code
//Little more code
//Little more code
if(IsManager || IsTeamLead)
{
//Veiew this content;
}
bool isManagerOrTeamLead = IsManager || ITeamLead;
然后...
if(isManagerOrTeamLead)
{
//Veiew this resticted content on the application;
}