在VS 2017中调试.NET Core控制台应用程序时,我无法进行编辑,然后设置下一条语句。它给了我标题中提到的错误:
例如,如果我在注释所指示的位置设置断点,然后调试并修改断点正上方第一行中的字符串,则会收到错误消息:
static void Main(string[] args)
{
string x = "foo"; // modify this after debug breaks.
string y = "bar"; // breakpoint here
}
Run Code Online (Sandbox Code Playgroud)
注意:这可以在.NET Framework控制台应用程序中按预期工作。
当我用谷歌搜索该OP的标题时,即使我将错误消息中的两个句子拆分成单独的带引号的字符串,也不会得到零结果。当我在Google中没有引号的时候,我得到的许多结果都没有提供答案。例如,这是相似的,因为它以“无法设置下一条语句”开始,但其余部分则不同。 这也是相似的,但第一句话之后又有所不同。
是什么原因造成的?
当项目不使用命名空间时,有没有办法告诉编译器使用静态类型而不是变量?
例如,我有一个名为User的类,它有各种静态和非静态方法.假设有一个静态方法被调用GetUser().
我试图User.GetUser()从一个方法调用该方法,该方法也有一个名为User的范围变量(继承自基类).但是,编译器抱怨说它找不到,User.GetUser()因为它认为我指的是范围内的User变量.
如果这个项目使用名称空间,我可以这样做ns1.User.GetUser(),但在这种情况下这是不可行的.有没有办法可以告诉编译器我指的是User类型而不是User变量?
我在运行时动态添加两个控件,但只显示第一个控件.
这是代码:
Label tempLab = new Label();
tempLab.text = "Test Label";
MyControl.Controls.Add(tempLab);
tempLab.Location = new Point(5,5);
Button tempBut = newButton()
tempBut.text = "Test Button";
MyControl.Controls.Add(tempBut);
tempBut.Location = new Point(20,20);
Run Code Online (Sandbox Code Playgroud)
不是copypasta所以忽略带帽的语法错误. 有任何想法吗 ?
它们被添加到组框中.我已经尝试将它们添加到面板或只是表单,并出现相同的问题.我不需要事件处理程序,所以请不要引用该要求.
我有一个关于枚举的问题,代码如下:
namespace space
{
public enum MyEnums
{
Enum1,Enum2,...
}
}
namespace space
{
public class MyClass
{
public enum MyEnums
{
Enum1,Enum2,...
}
}
}
Run Code Online (Sandbox Code Playgroud)
有什么区别以及如何使用它们?
假设我们有对象列表
List<int> list = new List<int>() { 1,1,1,2,3,3,3,2,2,2,1,1 };
Run Code Online (Sandbox Code Playgroud)
获得以下结果列表的最优雅的方法是什么?
{1,2,3,2,1}
Run Code Online (Sandbox Code Playgroud) 我无法找到如何将光标更改为"指针"或悬停图像时调用的任何内容.
我尝试使用MouseOver,但我无法让它工作.这是我目前的代码;
private void image_Phone_MouseOver(object sender, EventArgs e)
{
Cursor.Current = Cursors.Hand;
}
Run Code Online (Sandbox Code Playgroud)
但是,光标不会改变.
如果我有2个对象集合,是否可以在一个查询中有效地加入它们并从中选择它们?
例如:
var collection1 = GetSomeData();
var collection2 = GetSomeMoreData();
var myResult = from x in collection1
from y in collection2
where x.SomeProperty = "Yes"
where y.SomeProperty = "Yes"
select x, select y;
Run Code Online (Sandbox Code Playgroud)
GetSomeData,GetSomeMoreData都回归IEnumerable<MyType>
显然这不会编译......但希望它能说明我正在尝试做什么......
这对我来说不是一个重要的概念,但我只是想知道我是否可以在linq select语句之后对新对象进行强类型,而不是在C#. 这是一个示例,当然已经不复存在了,但它讲述了这个概念:
public class DisplayAddress { public int AddressId; public string ShortAddress; }
List<DisplayAddress> shortAddresses =
(from la in longAddresses
join ca in customerAddresses
on la.AddressId equals ca.AddressId
where ca.CustomerId == selectedCustomer
select new { new DisplayAddress() {AddressId = la.AddressId, ShortAddress = la.Line1 + " " + la.City + " " + la.State}}).Tolist<DisplayAddress>();
Run Code Online (Sandbox Code Playgroud) using关键字用于正确处理托管资源和非托管资源.
我很困惑何时使用using关键字.
例如,using用于托管资源,例如Connection对象.
它用于非托管资源,如下所示:
using (Font font1 = new Font("Arial", 10.0f))
{
byte charset = font1.GdiCharSet;
}
Run Code Online (Sandbox Code Playgroud)
使用using关键字时是否有一般的经验法则?是否应该用于所有物体,以便妥善处理?如何判断哪些对象是using关键字的主要候选者?
我创建了一个方法,允许我找到下一个空Box:
public int CheckBox(int boxNum) {
int BoxNumber = 0;
TextBox[] itemBoxArray = new TextBox[] { itemBox0, itemBox1, itemBox2, itemBox3, itemBox4, itemBox5, itemBox6, itemBox7,
itemBox8, itemBox9,itemBox10,itemBox11,itemBox12,itemBox13,itemBox14,itemBox15,};
for (int i = 0; i < itemBoxArray.Length; i++)
{
if (String.IsNullOrEmpty(itemBoxArray[i].Text))
{
BoxNumber = i;
i = 15;
}
}
return BoxNumber;
}
Run Code Online (Sandbox Code Playgroud)
接下来我创建了一个按钮来检查空盒子是什么,我想在这个盒子里输入一些内容,但是我找不到将转换带有空盒号的字符串转换为该文本框的方法:
private void StandAroundRebar_Click(object sender, EventArgs e)
{
int emptybox = CheckBox(0);
string emptyboxString = emptybox.ToString();
string newbox = "itemBox" + emptyboxString;
MessageBox.Show("TextBox # " + newbox + " is …Run Code Online (Sandbox Code Playgroud) c# ×10
.net ×3
linq ×2
winforms ×2
algorithm ×1
class ×1
collections ×1
debugging ×1
difference ×1
enums ×1
namespaces ×1
textbox ×1