Tag: C#的

VB.NET相当于C#“As”

C# As关键字的VB.NET中的等效内容如下所示? var x = y as String; if (x == null) …

Endianness是什么时候成为一个因素?

从我所理解的字节顺序来看,组成多字节字的字节在顺序上是不同的,至less在最典型的情况下是这样。 因此,一个16位整数可能被存储为0xHHLL或0xLLHH 。 假设我没有这个错误,我想知道什么时候Endianness在两台计算机之间发送信息的时候成为一个主要的因素,Endian可能不一样。 如果我发送一个短整数1,以char数组的forms,没有更正,它是否被接收并解释为256? 如果我使用下面的代码分解和重新构造短整数,endianness不再是一个因素? // Sender: for(n=0, n < sizeof(uint16)*8; ++n) { stl_bitset[n] = (value >> n) & 1; }; // Receiver: for(n=0, n < sizeof(uint16)*8; ++n) { value |= uint16(stl_bitset[n] & 1) << n; }; 是否有一个标准的方式来补偿sorting? 提前致谢!

初始化一个结构为0

如果我有这样的结构: typedef struct { unsigned char c1; unsigned char c2; } myStruct; 什么是最简单的方法来初始化这个结构为0? 以下就足够了吗? myStruct _m1 = {0}; 或者我需要显式初始化每个成员为0? myStruct _m2 = {0,0};

等待和ContinueWith之间的区别

有人可以解释,如果await和ContinueWith是同义或不在下面的例子。 我正在尝试第一次使用TPL,并一直在阅读所有的文档,但不明白其中的差别。 等待 : String webText = await getWebPage(uri); await parseData(webText); 继续 : Task<String> webText = new Task<String>(() => getWebPage(uri)); Task continue = webText.ContinueWith((task) => parseData(task.Result)); webText.Start(); continue.Wait(); 在特定的情况下比其他人更喜欢吗?

stringc_str()与数据()

我已经读了几个地方, c_str()和data() (在STL和其他实现)之间的区别是, c_str()总是空终止,而data()不是。 就我在实际实现中看到的,它们要么执行相同的操作,要么调用c_str() 。 我在这里错过了什么? 在哪种情况下使用哪一种更正确?

模板类和类模板有什么区别?

模板类和类模板有什么区别?

在C#中,如何实例化一个方法内传递的genericstypes?

我如何实例化typesT在我的InstantiateType<T>方法下面? 我得到的错误: “T”是一个“types参数”,但像一个“variables”使用。 : (SCROLL DOWN FOR REFACTORED ANSWER) using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace TestGeneric33 { class Program { static void Main(string[] args) { Container container = new Container(); Console.WriteLine(container.InstantiateType<Customer>("Jim", "Smith")); Console.WriteLine(container.InstantiateType<Employee>("Joe", "Thompson")); Console.ReadLine(); } } public class Container { public T InstantiateType<T>(string firstName, string lastName) where T : IPerson { […]

路由:当前的行动请求在以下行动方法之间不明确

我有一个名为Browse.chtml的视图,用户可以在其中inputsearch词,或者将search词留空。 当inputsearch字词时,我想直接将页面指向http://localhost:62019/Gallery/Browse/{Searchterm} ,当没有input时,我想直接将浏览器指向http://localhost:62019/Gallery/Browse/Start/Here 。 当我尝试这个,我得到的错误: 当前在控制器types“GalleryController”上的“浏览”操作请求在以下操作方法之间是不明确的:System.Web.Mvc.ActionResulttypes为AutoApp_MVC.Controllers.GalleryController的Browse(System.String)System.Web.Mvc.ActionResult Browse (Int32,System.String)typesAutoApp_MVC.Controllers.GalleryController 我用MVC所做的一切都是第一次。 我不确定还有什么要尝试在这一点上。 public ActionResult Browse(string id) { var summaries = /* search using id as search term */ return View(summaries); } public ActionResult Browse(string name1, string name2) { var summaries = /* default list when nothing entered */ return View(summaries); } 我也在Global.asax.cs中有这个: routes.MapRoute( "StartBrowse", "Gallery/Browse/{s1}/{s2}", new { […]

“折叠”LINQ扩展方法在哪里?

我在MSDN的Linq中find了一个我想使用的叫做Fold()的整洁方法。 他们的例子: double[] doubles = { 1.7, 2.3, 1.9, 4.1, 2.9 }; double product = doubles.Fold((runningProduct, nextFactor) => runningProduct * nextFactor); 不幸的是,我无法得到这个编译,无论是在他们的例子或我自己的代码,我找不到在MSDN其他地方(如Enumerable或数组扩展方法)提到这种方法。 我得到的错误是一个普通的老“不知道任何关于”的错误: error CS1061: 'System.Array' does not contain a definition for 'Fold' and no extension method 'Fold' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or […]

什么是replaceC中的string的函数?

给定一个(char *)string,我想查找所有出现的子string,并用替代stringreplace它。 我没有看到任何简单的函数在<string.h>中实现