相关疑难解决方法(0)

C#中两个问号共同意味着什么?

跨越这行代码:

FormsAuth = formsAuth ?? new FormsAuthenticationWrapper();
Run Code Online (Sandbox Code Playgroud)

这两个问号意味着什么,是某种三元运算符?谷歌很难找到.

c# null-coalescing-operator

1540
推荐指数
16
解决办法
37万
查看次数

?? Null Coalescing Operator - >合并是什么意思?

我很想撒谎并说英语是我的第二语言,但事实是我只是不知道'合并'是什么意思.我知道??C#中的"做什么",但这个名字对我来说没有意义.

我查了一下这个词,我理解它是'join'的同义词.'Null Join Operator'仍然没有意义.

有人可以开导我吗?

c# terminology coalesce null-coalescing-operator

44
推荐指数
4
解决办法
4472
查看次数

是什么 "??" 运营商?

我想知道代码中的??标志C#.它是为了什么?我该如何使用它?

怎么样int??它是一个可以为空的int吗?

也可以看看:

?? Null Coalescing Operator - >合并是什么意思?

c# coalesce operators null-coalescing-operator

31
推荐指数
7
解决办法
2729
查看次数

奇怪的运算符优先级与?? (null合并运算符)

最近我有一个奇怪的错误,我在那里连接一个字符串int?然后添加另一个字符串.

我的代码基本上相当于:

int? x=10;
string s = "foo" + x ?? 0 + "bar";
Run Code Online (Sandbox Code Playgroud)

令人惊讶的是,这将运行和编译没有警告或不兼容的类型错误,这将是:

int? x=10;
string s = "foo" + x ?? "0" + "bar";
Run Code Online (Sandbox Code Playgroud)

然后这会导致意外的类型不兼容错误:

int? x=10;
string s = "foo" + x ?? 0 + 12;
Run Code Online (Sandbox Code Playgroud)

这个更简单的例子也是如此:

int? x=10;
string s = "foo" + x ?? 0;
Run Code Online (Sandbox Code Playgroud)

有人能解释一下这对我有用吗?

c# types null-coalescing-operator

22
推荐指数
2
解决办法
2502
查看次数

<??>符号在C#.NET中的含义是什么?

可能重复:
什么是"??"运算符?

我看到一行代码表明 -

return (str ?? string.Empty).Replace(txtFind.Text, txtReplace.Text);
Run Code Online (Sandbox Code Playgroud)

我想知道这条线的确切含义(即??部分)..

.net c# symbols

8
推荐指数
2
解决办法
7198
查看次数

什么"??" 意思?

我正在看ASP.NET MVC 1.0生成的代码,并且想知道; 双重问号意味着什么?

// This constructor is not used by the MVC framework but is instead provided for ease
// of unit testing this type. See the comments at the end of this file for more
// information.
public AccountController(IFormsAuthentication formsAuth, IMembershipService service)
{
    FormsAuth = formsAuth ?? new FormsAuthenticationService();
    MembershipService = service ?? new AccountMembershipService();
}
Run Code Online (Sandbox Code Playgroud)

有关:

?? Null Coalescing Operator - >合并是什么意思?

c#

7
推荐指数
2
解决办法
976
查看次数

需要帮助了解此代码

我正在努力学习单元测试.我正在尝试对我在asp.net mvc 1.0中制作的一些Memembership内容进行单元测试.我一直在关注一本关于MVC的书,我对一些希望有人可以为我清理的东西感到困惑.

我正在使用Nunit和Moq作为我的框架.

问题1:

  public AuthenticationController(IFormsAuthentication formsAuth, MembershipProvider provider)
        {
            FormsAuth = formsAuth ?? new FormsAuthenticationWrapper();
            Provider = provider ?? Membership.Provider;
        }
Run Code Online (Sandbox Code Playgroud)

我有点困惑什么"??" 从来没有真正见过它.就像我甚至不知道这里发生了什么.就像他们通过界面然后"??" 标记发生并使一个新的FormsAuthenticationWraper成为?

问题2.

 public AuthenticationController(): this(null, null)
        {
        }
Run Code Online (Sandbox Code Playgroud)

我知道这是默认的构造函数,但我不确定为什么":this(null,null)"正在做.

就像它实施的是什么?这也是什么意思.除此之外,为什么不能将其排除在外?并按原样坚持默认构造函数.

问题3.

在书中(很快就是asp.net mvc 1.0),它讨论了如何实现Memembership提供程序将会有很多工作要做.所以他们使用moq模型框架让生活更轻松.

现在我的问题是他们不使用"FormsAuthentication"上的moq.他们改为创建一个界面

   public interface IFormsAuthentication
        {
            void SetAuthCookie(string userName, bool createPersistentCookie);
            void SignOut();


        }
Run Code Online (Sandbox Code Playgroud)

然后做一个包装

public class FormsAuthenticationWrapper:IFormsAuthentication {public void SetAuthCookie(string userName,bool createPersistentCookie){FormsAuthentication.SetAuthCookie(userName,createPersistentCookie); public void SignOut(){FormsAuthentication.SignOut(); }

}
Run Code Online (Sandbox Code Playgroud)

然后最后一个属性

   public IFormsAuthentication FormsAuth
        {
            get;
            private set;
        }
Run Code Online (Sandbox Code Playgroud)

他们只有会员资格

public static MembershipProvider Provider …

asp.net-mvc nunit unit-testing moq

2
推荐指数
1
解决办法
882
查看次数