我对C#非常陌生,我有一个常规问题:
应该在哪里存储与事件关联的常量?
它们应该包含在我定义EventArgs的相同位置吗?
作为解释,我想为名为"_difficulty"的私有字段定义不同的常量,并通过我重写的EventArgs类的构造函数来设置.
假设常量为,public const int EASY = 0,MEDIUM = 1,HARD = 2; (我假设命名约定是全部上限)
或者,我可以创建一个类似"DifficultyConstants"的类,然后将它们插入那里.
我只是对会议的内容感到好奇,并且对于遵循OOP最有意义.
我想知道调用短方法的开销是什么,或者代码是否会以任何方式进行优化,如果它与getter的成本不同?
我只举一个例子,因为很难解释.
我有一个ClaimsManager用于获取特定声明并返回它们的网站.从另一个获得一个声明的过程只有一个ClaimsType字符串.
public string GetClaimValueByType(string ClaimType)
{
return (from claim in _claimsIdentity.Claims
where claim.ClaimType == ClaimType
select claim.Value).SingleOrDefault();
}
/*Again would this be better or worse if I wanted to be able to choose if
I want the claim versus the value?
public Claim GetClaimByType(string ClaimType)
{
return (from claim in _claimsIdentity.Claims
where claim.ClaimType == ClaimType
select claim).SingleOrDefault();
}
public string GetClaimValueByType(string ClaimType)
{
return GetClaimByType(ClaimType).Value;
}
*/
public string GetEmail()
{
return GetClaimValueByType(ClaimTypes.Email);
}
/* Or should I …Run Code Online (Sandbox Code Playgroud)