在某种程度上,一个不那么容易的错误已经潜入这段代码,而我不知道修复它:
static void Main(string[] args)
{
Bitmap bm = new Bitmap(1, 1);
bm.SetPixel(1, 1, Color.AliceBlue);
bm.Save("C:\\Users\\Lasse\\Pictures\\Midlertidigt\\hej.jpeg", System.Drawing.Imaging.ImageFormat.Jpeg);//
Console.ReadLine();
}
Run Code Online (Sandbox Code Playgroud)
例外:
System.Drawing.dll中发生未处理的"System.ArgumentOutOfRangeException"类型异常
附加信息:参数必须为正且<宽度.
我正在尝试开发一个Web应用程序,它将文件发送到服务器(在这种情况下,服务器是本地服务器)。但是,当我尝试发送文件时,它总是给出:
DirectoryNotFoundException:找不到路径的一部分。
我已经确认该文件夹确实存在。并且为了确保,我在复制之前创建了目录,但是仍然出现错误。有人可以帮忙吗?这是代码:
string FileName = System.IO.Path.GetFileName("c:\\test\\Sample.txt");
string SaveLocation = HttpContext.Current.Server.MapPath("Uploadfile") + "\\";
if (System.IO.Directory.Exists(SaveLocation))
{
System.IO.Directory.CreateDirectory(SaveLocation);
System.IO.File.Copy("C:\\test\\Sample.txt", SaveLocation, true);
}
Run Code Online (Sandbox Code Playgroud)
的值为SaveLocation:
C:\ Users \ Nerd \ Documents \ Visual Studio 2012 \ Projects \ WebApplication3 \ WebApplication3 \ Uploadfile \
我将在运行时动态创建n个扩展器控件,如下所示,
theExpanderCaption[counter] = new TextBlock();
theExpanderCaption[counter].FontWeight = FontWeights.Bold;
theExpanderCaption[counter].Text = ITEMIMP.DataConstants.GroupIds.GetGroupCaption(group.GroupId);
theGroupExpander[counter] = new Expander();
theGroupExpander[counter].Header = theExpanderCaption[counter];
theGroupExpander[counter].Margin = new Thickness(10);
theGroupExpander[counter].HorizontalAlignment = HorizontalAlignment.Left;
theGroupExpander[counter].IsExpanded = true;
theGroupExpander[counter].Content = this.theGroupGrids[counter];
theGroupExpander[counter].Style = null;
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,我使用文本块数组来设置扩展器头(使其变为粗体).这里的缺点是我必须使用n no 文本块控件.有没有其他方法来实现这一目标?
当我运行我的程序时,它直接运行并且不允许我输入用户输入.
这是我的主要功能
[STAThread]
static void Main()
{
valueCalculation(validateX(), validateY(), validateZ());
}
Run Code Online (Sandbox Code Playgroud)
这是我的validateX函数
public static String validateX()
{
Console.WriteLine("Enter your X value: ");
string x = null;
do
{
x = Console.ReadLine();
//do stuff
}
while(x != null);
return x;
}
Run Code Online (Sandbox Code Playgroud) 我在控制台应用程序中收到以下语法错误:
非静态字段,方法或属性"ConsoleApplication1.Program.db"需要对象引用
我怎样才能解决这个问题?我已经阅读了关于制作db静态的建议,但我并不完全理解.
class Program
{
private CallContext db = new CallContext();
private BreachContext bc = new BreachContext();
static void Main(string[] args)
{
var snapshot = db.Calls.Where(x => x.team == "T1").ToList();
Run Code Online (Sandbox Code Playgroud) 我需要从源序列中提取所有负序子.例如,我有:
{-2,-2,5,9,1,-6,-7,-2,5,11,-2}
在结果中我想得到这些序列:
{-2,-2},{ - 6,-7,-2}和{-2}
是否可以使用LINQ解决任务?
当我{0}在下面的代码中使用时:
class Program
{
double width;
double height;
public void getData() {
Console.WriteLine("Enter Width:");
width = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter Height:");
height = Convert.ToDouble(Console.ReadLine());
}
public double calcArea() {
return width * height;
}
public void display() {
Console.WriteLine("Area is : {0}",calcArea());
}
}
class Area
{
static void Main(string[] args)
{
Program p = new Program();
p.getData();
p.display();
}
}
Run Code Online (Sandbox Code Playgroud)
输出是:
输入宽度:
6
输入高度:
9
面积为:54
当我在这里使用{0}时:
class NewArea
{
static void Main(String[] args) {
double width;
double height; …Run Code Online (Sandbox Code Playgroud) 我正在为项目的每个 sql 调用创建新线程。有数百万个 sql 调用,因此我在新线程中调用一个过程来处理 sql 调用。
在此过程中,我想增加和减少一个计数器,以便我知道这些线程何时完成 SQL 查询。
令我惊讶的是,计数器的输出显示负值。如何?当我从 0 开始并在过程开始时加 1 并在过程结束时减 1 时?
这个 int 没有在程序的其他地方被调用。以下是代码。
public static int counter=0;
while(!txtstream.EndOfStream)
{
new Thread(delegate()
{
processline();
}).Start();
Console.WriteLine(counter);
}
public static void processline()
{
counter++;
sql.ExecuteNonQuery();
counter--;
}
Run Code Online (Sandbox Code Playgroud)
输出看起来像这样:
1
21
-2
-2
5
Run Code Online (Sandbox Code Playgroud) 我的登录系统有问题.
当我添加撇号字符(')时,我收到错误:
Microsoft.Practices.EnterpriseLibrary.Data.dll中发生未处理的"System.Data.SqlClient.SqlException"类型的异常异常
附加信息:字符串'''后面的未闭合引号.'''附近的语法不正确.
这是登录代码.这是单独使用用户名和密码,但它的工作原理.
public String getSenha(string user)
{
String Query = "SELECT senha FROM dbo.Login WHERE usuario = '" + user + "'"; //Comando
Conexao Connection = new Conexao(); //Instancia a classe conexao
object ret = Connection.QueryScalar(Query); //Executa o comando e salva o resultado em 'ret'
if (ret.GetType() == typeof(int))
return null;
else
return (string)ret;
}
public Boolean checkUser(string user)
{
String Query = "SELECT COUNT(usuario) FROM dbo.Login WHERE usuario = '" + user + "'"; …Run Code Online (Sandbox Code Playgroud) 当我尝试查询IList类型对象时,为什么以下代码不返回任何内容?
IList<Person> personRecord = new List<Person>
{
new Person{ Name = "Samuel"},
new Person{ Name = "Kenny Sammy"},
new Person{ Name = "Jame Sam Lee"}
};
var names = from b in personRecord
where personRecord.Any(d => d.Name == "Sam")
select b;
return names.ToList();
Run Code Online (Sandbox Code Playgroud)