我不知道该怎么办,因为错误在于Form1.Designer.cs,因为我没有调试程序部分的经验.
//Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(352, 246);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Generate Username";
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
this.ResumeLayout(false);
Run Code Online (Sandbox Code Playgroud) 在我的C#代码中,我使用XmlDocument 引用XML文件"file.xml",该文件与可执行文件本身位于同一目录中.
该应用程序在VS中运行得非常好,但是当我尝试使用Task Scheduler运行应用程序时,我得到了一个System.IO.FileNotFoundException,即使一切都是一样的.
我使用引用文件@".\file.xml".这是特定于任务计划程序的一些奇怪的东西吗?使用适当的权限.
我有两节课.第一类是Parent,它有一个对象列表(Child).每个人Child都提到他的Parent班级.问题是如何通过构造函数实现此引用.
public sealed class Child
{
public Child(string id, string name, Parent parent)
{
Id = id;
Name = name;
Parent = parent;
}
public Parent ParentInstance { get; private set; }
public string Id { get; private set; }
public string Name { get; private set; }
}
public sealed class Parent
{
public Parent(string id, string name, IEnumerable<Child> children)
{
Id = id;
Name = name;
Children = children;
} …Run Code Online (Sandbox Code Playgroud) 我正在使用linq查询集合,并datetime使用以下代码按属性对数据进行分组:
var querty = from post in ds.Appointments
group post by new
{
Year = post.DateOfVisit.Year,
Month = post.DateOfVisit.Month
};
Run Code Online (Sandbox Code Playgroud)
当使用匿名类型时,一切都很好.但是,如果我定义自己的类
class YearMonth
{
public int Year;
public string Month;
public YearMonth(int year, int month)
{
Year = year;
Month = month;
}
public override string ToString()
{
return string.Format("{0}-{1}",Year,Month);
}
}
Run Code Online (Sandbox Code Playgroud)
并相应地修改我的查询
var querty = from post in ds.Appointments
group post by new YearMonth(post.DateOfVisit.Year,
post.DateOfVisit.Month);
Run Code Online (Sandbox Code Playgroud)
然后分组不起作用,我得到一个简单的对象列表.为什么?
我在这里维护这个代码,通常有如下模式:
StringBuilder result = new StringBuilder();
result.Append("{=" + field.Name + "={");
Run Code Online (Sandbox Code Playgroud)
这样做时,看起来像是浪费了很多无用的对象构造,我想重写一下:
result.Append("{=").Append(field.Name).Append("={");
Run Code Online (Sandbox Code Playgroud)
第一个版本对GC造成的压力更大是否正确?或者是否在C#编译器中使用字符串文字进行了一些优化,其中串联字符串与字符串文字不会创建临时对象?
我正在尝试计算给定路径的所有子文件夹中的文件总数.我正在使用递归函数调用.可能是什么原因?
码:
int iCount =0;
getFileCount(_dirPath, out iCount);
private void getFileCount(string _path, out int iCount )
{
try
{
// gives error :Use of unassigned out parameter 'iCount' RED Underline
iCount += Directory.GetFiles(_path).Length;
foreach (string _dirPath in Directory.GetDirectories(_path))
getFileCount(_dirPath, out iCount);
}
catch { }
}
Run Code Online (Sandbox Code Playgroud) 我的一些测试类运行时间超过一分钟,我无法完成它们,因为它取消了它说:
取消测试运行:超出60000毫秒的测试运行超时.
这是可配置的吗?我正在使用最新版本:
我有一些工作代码从数据库中检索数据.我有兴趣为我的解决方案获得更好的代码.有没有办法将两个查询组合成一个或类似的东西?
Dim customerTitlesAndIDs = contex.CustomerTable.Select(Function(row) New
With {.ID = row.ID, .CustomerTitle = row.Title}).ToList()
Dim cutomerIdPayment = contex.CustomerPayments.Select(Function(table) New
With
{
.ID = table.CustomerID,
.Range = table.PaymentsRange,
.Values = table.Values
}).ToList()
Dim customerInfos As New List(Of SCustomerInfo)
For Each customer In customerTitlesAndIDs
Dim cID As Integer = customer.ID
customerInfo.Add(New SCustomerInfo(CreateCustomerTable(), cID, customer.CustomerTitle))
For Each cutomerPayments In cutomerIdPayment
If cutomerPayments.ID = cID Then
Dim rangeValue(1) As Object
rangeValue(0) = cutomerPayments.Range
rangeValue(1) = cutomerPayments.Values
Dim dtRow As DataRow = customerInfos.Last().PaymentTable.NewRow()
dtRow.ItemArray = rangeValue …Run Code Online (Sandbox Code Playgroud) 嗨我在C#win表单应用程序中重置Timer控件时遇到问题.
我正在开发一个简单的倒数计时器.

当我点击start它从59秒开始倒计时.我需要计时器从我点击Start按钮开始重启.
代码 timer1_tick
if (hours==0 && minutes==0 && seconds==0)
{
hours = 0;
minutes = 1;
seconds = 0;
}
else
{
if (seconds < 1)
{
seconds = 59;
if (minutes == 0)
{
minutes = 59;
if (hours != 0)
hours -= 1;
}
else
{
minutes -= 1;
}
}
else
seconds -= 1;
lblTime.Text = hours + @":" + minutes + @":" + seconds;
}
Run Code Online (Sandbox Code Playgroud)
和代码 btnStart_Click
timer1.Enabled = false; …Run Code Online (Sandbox Code Playgroud) 即使数据库初始化程序设置为CreateIfNotExists,我也总是遇到此异常.
Additional information: Cannot create file 'C:\\Users\\Krab\\Documents\\Visual Studio 2013\\Projects\\Customer_UI\\customers2.mdf' because it already exists. Change the file path or the file name, and retry the operation.
CREATE DATABASE failed. Some file names listed could not be created. Check related errors.
Run Code Online (Sandbox Code Playgroud)
为什么EF尝试创建数据库,即使它已经存在?
App.config中
<connectionStrings>
<add name="Customer.CustomersContext" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename='C:\\Users\\Krab\\Documents\\Visual Studio 2013\\Projects\\Customer_UI\\customers2.mdf';Integrated Security=True;Connect Timeout=30" providerName="System.Data.SqlClient" />
</connectionStrings>
Run Code Online (Sandbox Code Playgroud)
的DbContext:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Entity;
namespace Customer
{
public class CustomersContext : DbContext
{
public CustomersContext() : base("Customer.CustomersContext")
{ …Run Code Online (Sandbox Code Playgroud)