多维数组不实现IEnumerable ,还是它们呢?

由于我仍然不理解的原因( 参见这个SO问题 )CLR中的多维数组没有实现IEnumerable 。 所以以下不编译: var m = new int[2,2] {{1, 2}, {3, 4}}; var q = from e in m select e; 那怎么会在VB.NET中运行得很好呢? Sub Main() Dim m(,) As Integer = {{1, 2}, {3, 4}} Dim q = From e In m Select e For Each i In q Console.WriteLine(i) Next End Sub 更新: 以下代码有效,因为C#编译器将foreach替换for循环以遍历每个维度。 […]

如何在SqlCommand中设置未命名的SQL参数

如果我将未命名的参数添加到我的SqlCommand ,如何在SqlCommand上设置参数值? 我使用命名参数时没有问题,我可以在其中执行SqlCommand.Parameters.AddWithValue() 。 例: Select * from sometable where SomeValue=? and AnotherValue=?

c#.net更改标签文本

您好我试图使用此代码但由于某种原因它不起作用。 真的需要帮助。 问题是当我进入网站时,标签不会从“标签”更改名称。

将.Net Framework 4.0添加到安装项目中

可能重复: 为C#应用程序创建一个安装程序,并在设置中包含.NET Framework安装程序 我有.net框架4.0的Windows应用程序,我想将.net框架4.0添加到安装文件.. 我已经使用先决条件添加了它,但是当我开始下载它时,它需要互联网连接。 和文件大约250 MB 是否有可能当我开始安装应用程序时,它还会自动安装.net框架?

Newtonsoft Json.net – 如何序列化流的内容?

我需要转换为内存流的JSON 任意内容 。 这是我想要做的一个简单示例: class Program { class TestClass { public int Test1;} static void Main(string[] args) { var ms = new MemoryStream(); var writer = new StreamWriter(ms); writer.Write(new TestClass()); writer.Flush(); ms.Position = 0; var json = JsonConvert.SerializeObject(/*???*/, Formatting.Indented); Console.Write(json); Console.Read(); } } 不知道要传递给SerializeObject方法的内容。 如果我传递MemoryStream(变量ms)我得到一个错误: Newtonsoft.Json.dll中出现未处理的“Newtonsoft.Json.JsonSerializationException”类型exception 附加信息:从’System.IO.MemoryStream’上的’ReadTimeout’获取值时出错。 是否可以序列化流的任意内容? 谢谢

如何在C#中搜索String数组中的子字符串

如何在String数组中搜索Substring? 我需要在字符串数组中搜索一个Substring。 字符串可以位于数组(元素)的任何部分或元素内。 (字符串的中间)我试过: Array.IndexOf(arrayStrings,searchItem)但是searchItem必须是在arrayStrings中找到的精确匹配。 在我的例子中,searchItem是arrayStrings中完整元素的一部分。 string [] arrayStrings = { “Welcome to SanJose”, “Welcome to San Fancisco”,”Welcome to New York”, “Welcome to Orlando”, “Welcome to San Martin”, “This string has Welcome to San in the middle of it” }; lineVar = “Welcome to San” int index1 = Array.IndexOf(arrayStrings, lineVar, 0, arrayStrings.Length); // index1 mostly […]

无法加载文件或程序集FSharp.Core,Version = 4.0.0.0 Azure Web Role

我已经在我的项目( http://mcapinet.codeplex.com/ )中为Mailchimp添加了NuGet包,这个包依赖于FSharp.Core,所以当我在我的本地机器上安装包时它已被添加为参考(和使用Azure模拟器)一切正常,但是当我在Azure上发布我的Cloud Service时(注意:我正在使用Visual Studio Online进行持续部署)我在访问网站时遇到了这个错误: Could not load file or assembly ‘FSharp.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ or one of its dependencies. The system cannot find the file specified. 并且FSharp.Core的属性“Copy local”设置为True。 我怎么解决这个问题? 编辑 在部署期间,我可以看到此警告: The project ‘Interface.Web’ is dependent on the following assembly: C:\a\src\TFS\packages\FSharp.Core.4.0.0\lib\FSharp.Core.dll. This assembly is not in the package. To make sure that the […]

等待任务中的Task.WhenAll()等待

我的问题是当一个Task有一个Task.WhenAll()调用(运行其他任务)时,WhenAll()行让消费代码继续执行,这与我的预期不同。 因此,当命中Task.WhenAll()时,以下代码立即输出“finished”,而不是在其参数中的所有任务完成之后。 // Just a simple async method public Task DoWorkAsync() { return Task.Factory.StartNew( () => { // Working }); } // This one used the previous one with Task.WhenAll() public Task DoLoadsOfWorkAsync() { return Task.Factory.StartNew( async () => { // Working // This line makes the task return immediately await Task.WhenAll(DoWorkAsync(), DoWorkAsync()); // Working […]

为RESTful WCF配置SSL绑定。 怎么样?

我当前的配置如下: 当我为我的网站配置了http 和 https绑定时,这种方法有效。 我通过https连接到服务,一切都很好。 现在我想完全删除IIS上的http绑定。 我开始得到这样的错误: 找不到与绑定WebHttpBinding的端点的方案http匹配的基址。 注册的基地址方案是[https]。 [InvalidOperationException:找不到与绑定WebHttpBinding的端点的scheme http匹配的基址。 注册的基地址方案是[https]。] System.ServiceModel.ServiceHostBase.MakeAbsoluteUri(Uri relativeOrAbsoluteUri,Binding binding,UriSchemeKeyedCollection baseAddresses)+16582113 System.ServiceModel.Description.ConfigLoader.ConfigureEndpointAddress(ServiceEndpointElement serviceEndpointElement,ServiceHostBase host,ServiceEndpoint endpoint)+117 System.ServiceModel.Description.ConfigLoader.ConfigureEndpoint(StandardEndpointElement standardEndpointElement,ServiceEndpointElement serviceEndpointElement,ContextInformation context,ServiceHostBase host,ServiceDescription description,ServiceEndpoint&endpoint,Boolean omitSettingEndpointAddress)+937 System.ServiceModel.Description.ConfigLoader.LookupEndpoint(ServiceEndpointElement serviceEndpointElement,ContextInformation context,ServiceHostBase host,ServiceDescription description,Boolean omitSettingEndpointAddress)+8728167 System.ServiceModel.Web.WebServiceHost.AddAutomaticWebHttpBindingEndpoints(ServiceHost host,IDictionary`2 implementedContracts,String multipleContractsErrorMessage,String standardEndpointKind)+982 System.ServiceModel.Web.WebServiceHost.OnOpening()+311 System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)+612 System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath)+255 System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath)+1172 [ServiceActivationException:由于编译期间发生exception,无法激活服务’/ DEMO / mobile’。 exception消息是:找不到与绑定WebHttpBinding的端点的scheme http匹配的基址。 注册的基地址方案是[https] ..] System.Runtime.AsyncResult.End(IAsyncResult result)+901424 […]

在Window Application中使用HttpContext.Current.Server.MapPath?

我可以在窗口应用程序中执行类似的操作吗? HttpContext.Current.Server.MapPath(“Email/ForgotPassword.txt”)); 该项目是基于Web的应用程序。 我的下一个项目基本上是一个窗口服务…… 寻求建议。