草庐IT

int-type

全部标签

c# - 使用 LINQ 将 Dictionary<String,Int> 转换为 Dictionary<String,SomeEnum>?

我正试图找到一个LINQoneliner,它接受一个Dictionary并返回一个Dictionary....这可能不可能,但会很好。有什么建议吗?编辑:ToDictionary()是显而易见的选择,但你们中有人实际尝试过吗?在Dictionary上它的工作方式与在Enumerable上的工作方式不同...您不能将键和值传递给它。编辑#2:哦,我在这行上面有一个错字,导致编译器搞砸了。一切顺利。 最佳答案 它通过简单的转换直接工作。Dictionaryinput=newDictionary();//TransforminputDic

c# - 没有无参数构造函数的类型的 Activator.CreateInstance(Type)

这个问题在这里已经有了答案:CreatinginstanceoftypewithoutdefaultconstructorinC#usingreflection(4个答案)关闭9年前。阅读工作中的现有代码,我想知道这怎么能行得通。我在程序集中定义了一个类:[Serializable]publicclassA{privatereadonlystring_name;privateA(stringname){_name=name;}}在另一个程序集中:publicvoidf(Typet){objecto=Activator.CreateInstance(t);}和那个简单的调用f(typeo

c# - 如何解决错误 :the type does not appear to implement microsoft. practices.servicelocation.iservicelocator?

我是MVC的新手,我正在关注“AdamFreeman的PROASP.NETMVC4”。我目前正在研究它的第6章。我正在学习如何使用MVC4中的Ninject进行依赖注入(inject)。我已经按照书中的描述创建了应用程序。现在我不明白为什么会出现以下错误:该类型似乎没有实现microsoft.practices.servicelocation.iservicelocator这是我的Controller代码:publicclassHomeController:Controller{privateProduct[]products={newProduct{Name="Kayak",Cate

c# - 将列表<int> 转换为连接的整数字符串?

我有一个值为3,99,6的int数组。如何使用linq将数组转换为字符串3,99,6? 最佳答案 int[]list=new[]{3,99,6};strings=string.Join(",",list.Select(x=>x.ToString()).ToArray());编辑,C#4.0在C#4.0中,还有一个重载string.Join,最终允许传递一个IEnumerable或IEnumerable直接地。无需创建数组,也无需调用ToString(),它被隐式调用:strings=string.Join(",",list);对字符

c# - 如何将字节数组转换为 int 数组?

如何将byte数组转换为int数组?我有一个包含144个项目的字节数组,由于我缺乏经验,我尝试过的方法效率很低。如果之前有人回答过这个问题,我很抱歉,但我在任何地方都找不到好的答案。 最佳答案 简单://WhereyourBytesisaninitializedbytearray.int[]bytesAsInts=yourBytes.Select(x=>(int)x).ToArray();确保包含System.Linq和using声明:usingSystem.Linq;如果LINQ不是您的菜,您可以改用它:int[]bytesAsI

c# - 区分 short、int、long 真的很重要吗?

在我的C#应用程序中,我想知道对较小的数字使用short,对较大的数字使用int等是否真的很重要。内存消耗真的很重要吗? 最佳答案 除非您以某种结构将大量这些打包在一起,否则它可能根本不会影响内存消耗。使用特定整数类型的最佳理由是与API的兼容性。除此之外,只需确保您选择的类型有足够的范围来涵盖您需要的值。除此之外,对于简单的局部变量,它并不重要。 关于c#-区分short、int、long真的很重要吗?,我们在StackOverflow上找到一个类似的问题:

c# - 如何使用 EF 迁移将 int ID 列更改为 Guid?

我正在使用EF代码优先方法并想将Id字段更改为guid但似乎无法通过以下错误。这是我的第一次迁移:publicpartialclassCreateDownloadToken:DbMigration{publicoverridevoidUp(){CreateTable("dbo.DownloadTokens",c=>new{Id=c.Int(nullable:false,identity:true),FileId=c.Int(),UserId=c.String(nullable:false,maxLength:128),ValidUntil=c.DateTime(nullable:fal

c# - 错误 : Cannot implicitly convert type 'void' to 'System.Collections.Generic.List'

我正在尝试使用该控件从.ascx设置我的.ascx控件的属性。所以在我的一个包含此控件的.aspx中,我有以下代码试图设置我的嵌入式.ascx的ItemsList属性:Itemitem=GetItem(itemID);myUsercontrol.ItemList=newList().Add(item);我尝试设置的.ascx中的属性如下所示:publicListItemsList{get{returnthis.itemsList;}set{this.itemsList=value;}}错误:无法将类型“void”隐式转换为“System.Collections.Generic.List

c# - Linq-to-sql 错误 : 'int[]' does not contain a definition for 'Contains'

我有一个错误:错误2'int[]'不包含'Contains'的定义并且最佳扩展方法重载'System.Linq.Enumerable.Contains(System.Collections.Generic.IEnumerable,TSource)'有一些无效参数这是我的代码:publicpartialclassmymymy:System.Web.UI.Page{int[]validType={2,3,4,5,6,8,13,14,16,22};protectedvoidPage_Load(objectsender,EventArgse){}protectedvoidLinqDataSou

c# - x :Type not found in user control library

我正在尝试在WPF用户控件库项目中创建一个ResourceDictionary。当我添加以下样式时:我收到一条错误消息:Thetype'x:Type'wasnotfound.Verifythatyouarenotmissinganassemblyreferenceandthatallreferencedassemblieshavebeenbuilt.我将x声明为:xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"当我在WPF应用程序项目中而不是在UserControl库项目中创建资源字典时,这会起作用。知道为什么吗?