草庐IT

copy-assignment

全部标签

c# - CS0133 "The expression being assigned to ' identifier' must be constant”- 这背后的原因是什么?

有了很多C++背景,我已经习惯了编写以下内容:constintcount=...;//somenon-trivialstuffherefor(inti=0;i而且我希望在C#中也能正常工作。然而……byte[]buffer=newbyte[4];constintcount=buffer.Length;产生错误CS0133:分配给“count”的表达式必须是常量。我不明白。为什么那是无效的?int是一个值类型,不是吗?为什么我不能通过这种方式分配一个值并使变量不可更改? 最佳答案 因为C#中的const比C++中的const更多con

c# - 错误 : The Out Parameter must be assigned before control leaves the current method

发送回参数时出现此错误Error:TheOutParametermustbeassignedbeforecontrolleavesthecurrentmethod代码是publicvoidGetPapers(stringweb,outintId1,outintId2){SqlConnectionconn=newSqlConnection(ConnectionString());conn.Open();SqlCommandcmd=newSqlCommand("GetPapers",conn);cmd.CommandType=CommandType.StoredProcedure;cmd.

c# - 错误 : The Out Parameter must be assigned before control leaves the current method

发送回参数时出现此错误Error:TheOutParametermustbeassignedbeforecontrolleavesthecurrentmethod代码是publicvoidGetPapers(stringweb,outintId1,outintId2){SqlConnectionconn=newSqlConnection(ConnectionString());conn.Open();SqlCommandcmd=newSqlCommand("GetPapers",conn);cmd.CommandType=CommandType.StoredProcedure;cmd.

c# - 错误 MSB3027 : Could not copy "C:\pagefile.sys" to "bin\roslyn\pagefile.sys". 超过重试次数 10。失败

我一直在使用VS2013时遇到此错误:Couldnotcopy"C:\pagefile.sys"to"bin\roslyn\pagefile.sys".Exceededretrycountof10.Failed.Unabletocopyfile"C:\pagefile.sys"to"bin\roslyn\pagefile.sys".Theprocesscannotaccessthefile请帮帮我。 最佳答案 如thisanswerfromPramod'scomment中所示问题源于Microsoft.CodeDom.Provide

c# - 错误 MSB3027 : Could not copy "C:\pagefile.sys" to "bin\roslyn\pagefile.sys". 超过重试次数 10。失败

我一直在使用VS2013时遇到此错误:Couldnotcopy"C:\pagefile.sys"to"bin\roslyn\pagefile.sys".Exceededretrycountof10.Failed.Unabletocopyfile"C:\pagefile.sys"to"bin\roslyn\pagefile.sys".Theprocesscannotaccessthefile请帮帮我。 最佳答案 如thisanswerfromPramod'scomment中所示问题源于Microsoft.CodeDom.Provide

查看Kafka集群下所有的topic报错“Timed out waiting for a node assignment. Call: listTopics“

异常[root@centos7_101kafka]#bin/kafka-topics.sh--bootstrap-server192.168.88.142:9092--list\^HErrorwhileexecutingtopiccommand:Timedoutwaitingforanodeassignment.Call:listTopics[2022-04-1015:13:13,560]ERRORorg.apache.kafka.common.errors.TimeoutException:Timedoutwaitingforanodeassignment.Call:listTopics(k

c# - 在 C# 构造函数中初始化什么更好 : initializer lists or assignment?

A类使用初始化列表将成员设置为参数值,而B类使用构造函数体内的赋值。只要我始终如一,任何人都可以给出更喜欢其中一个的理由吗?classA{String_filename;A(Stringfilename):_filename(filename){}}classB{String_filename;B(Stringfilename){_filename=filename;}} 最佳答案 第一个在C#中是不合法的。构造函数中冒号后唯一可以出现的两项是base和this。所以我会选择第二个。 关

c# - 在 C# 构造函数中初始化什么更好 : initializer lists or assignment?

A类使用初始化列表将成员设置为参数值,而B类使用构造函数体内的赋值。只要我始终如一,任何人都可以给出更喜欢其中一个的理由吗?classA{String_filename;A(Stringfilename):_filename(filename){}}classB{String_filename;B(Stringfilename){_filename=filename;}} 最佳答案 第一个在C#中是不合法的。构造函数中冒号后唯一可以出现的两项是base和this。所以我会选择第二个。 关

c# - 当源和目标是同一个数组时,Array.Copy 是否安全?

我目前正在使用Array.Copy来移动数组:Array.Copy(array,0,array,1,array.Length-1);它明显比使用循环更快。我知道其他语言(例如memcpy)中的类似函数是未定义的,或者当编译器过于激进时有时会中断。认为这在.NET中是安全的是否合理? 最佳答案 是的,它是安全的。是documented该方法在这种情况下应该如何表现:IfsourceArrayanddestinationArrayoverlap,thismethodbehavesasiftheoriginalvaluesofsource

c# - 当源和目标是同一个数组时,Array.Copy 是否安全?

我目前正在使用Array.Copy来移动数组:Array.Copy(array,0,array,1,array.Length-1);它明显比使用循环更快。我知道其他语言(例如memcpy)中的类似函数是未定义的,或者当编译器过于激进时有时会中断。认为这在.NET中是安全的是否合理? 最佳答案 是的,它是安全的。是documented该方法在这种情况下应该如何表现:IfsourceArrayanddestinationArrayoverlap,thismethodbehavesasiftheoriginalvaluesofsource