我有应该在启动任务中执行的示例控制台应用程序,我想通过批处理文件执行控制台应用程序,请知道执行它的正确语法.
我有这个Windows控制台应用程序:
using System;
using System.Text;
namespace ThreadLockSample
{
class Program
{
static void P1(System.Data.DataTable dt)
{
for (int i = 0; i < 100000; i++)
{
dt.Rows.Add(i);
}
}
static void P2(System.Data.DataTable dt)
{
for (int i = 100000; i < 200000; i++)
{
dt.Rows.Add(i);
}
}
static void Main(string[] args)
{
System.Data.DataTable dt = new System.Data.DataTable();
for (int i = 0; i < 200; i++)
dt.Columns.Add("Id " + i);
System.Threading.Thread t1 = new System.Threading.Thread(() => P1(dt));
System.Threading.Thread t2 = …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) 我正在尝试将相对较大的文件上传到FTP服务器(250-300mb).我在控制台应用程序中执行此操作.
当文件是几MB时,我的程序工作正常,但是大的文件导致:
System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.
Run Code Online (Sandbox Code Playgroud)
我试图设置超时,但我仍然得到错误.
知道如何修改我的代码,所以我没有得到错误?
我的上传代码:
using(var fs = File.OpenRead(zipFileName))
{
var ms = new MemoryStream();
ms.SetLength(fs.Length);
fs.Read(ms.GetBuffer(), 0, (int) fs.Length);
FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpUrl + "/" + zipFileName);
ftp.Credentials = new NetworkCredential(ftpUid, ftpPassword);
ftp.Timeout = 30000;
ftp.KeepAlive = true;
ftp.UseBinary = true;
ftp.Method = WebRequestMethods.Ftp.UploadFile;
byte[] buffer = new byte[ms.Length];
ms.Read(buffer, 0, buffer.Length);
ms.Close();
Stream ftpstream = ftp.GetRequestStream();
ftpstream.Write(buffer, 0, buffer.Length);
ftpstream.Close();
}
Run Code Online (Sandbox Code Playgroud) 我试图理解这种模式,行和列方程式如何,以便我可以做一个循环给我相同的图片.我不一定需要代码,只是模式的方式,我似乎无法理解它已经尝试编码它仍然我的结果是坏的...
当我的输入为1时,这就是结果

当我的输入为3时,这就是结果

当我的输入为15时,这就是结果

我知道我能做到这一点并且有效
string Dob; //string
Console.WriteLine("Enter date of Birth in format DD/MM/YYYY: ");
Dob = Console.ReadLine();
Run Code Online (Sandbox Code Playgroud)
但我想要这样的东西!预定义的方法或短路方式
DateTime Dob; //DateTime
Console.WriteLine("Enter date of Birth in format DD/MM/YYYY: ");
//What i am expecting, but is not possible as its DateTime
Dob = Console.ReadLine(); // expects a string
Run Code Online (Sandbox Code Playgroud)
是否有一种特定的方法可以直接从键盘获取Dob变量的日期.
在DateTime类中是否有预定义的方法?实现这一目标的最佳途径或最短途径是什么?
我正在尝试在Windows控制台应用程序中下载azure blob.当我构建和调试应用程序时,我的azure连接字符串抛出异常.这个字符串在我的其他asp.net应用程序中工作正常.
违规行是:
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["DefaultEndpointsProtocol=https;AccountName=xxxxx;AccountKey=xxxxx==;BlobEndpoint=https://xxxxx.blob.core.windows.net/;TableEndpoint=https://xxxxx.table.core.windows.net/;QueueEndpoint=https://xxxxx.queue.core.windows.net/;FileEndpoint=https://xxxxx.file.core.windows.net/"].ConnectionString);
Run Code Online (Sandbox Code Playgroud)
我的代码是:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Blob;
using System.Configuration;
using System.IO;
using System.Data;
using System.Data.SqlClient;
using System.Threading;
namespace CPGetAdverts
{
class Program
{
static void Main(string[] args)
{
// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["DefaultEndpointsProtocol=https;AccountName=xxxxx;AccountKey=xxxxx==;BlobEndpoint=https://xxxxx.blob.core.windows.net/;TableEndpoint=https://xxxxx.table.core.windows.net/;QueueEndpoint=https://xxxxx.queue.core.windows.net/;FileEndpoint=https://xxxxx.file.core.windows.net/"].ConnectionString);
// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve a reference to a container.
var container = blobClient.GetContainerReference("newadverts").ListBlobs(); …Run Code Online (Sandbox Code Playgroud) 我在C#的控制台应用程序中编写了这个do-while循环:
do
{
ThisHelp.ShowMenu();
userChoice = (char) Console.Read();
ThisHelp.Helpon(userChoice);
}while(ThisHelp.IsValid(userChoice) == false);
Run Code Online (Sandbox Code Playgroud)
该方法ThisHelp.ShowMenu()只有一堆Write + WriteLine方法,它们要求用户输入1到8的数字.该方法ThisHelp.Helpon()有一个开关,根据传递的用户输入,显示不同的文本.该方法ThisHelp.IsValid只检查用户输入是1到8之间的数字.
这是问题:在用户写入数字并按下ENTER后,循环的第一个语句在第二个语句至少执行一次之前执行3次.为什么会这样?
编辑:这是ThisHelp.IsValid方法的代码,如下所示:
public bool IsValid(char ch)
{
if (ch < '1' | ch > 8 & ch != 'q') return false;
else return true;
}
Run Code Online (Sandbox Code Playgroud) 我试图用控制台应用程序截取我的屏幕截图,然后将其保存到我的桌面但由于某种原因..它告诉我,我的剪贴板是空的时候显然它不是..如果你检查代码你可以看到我按PrintScreen,当您这样做时,它会将其保存到剪贴板.
using System;
using System.Drawing;
using System.Windows.Forms;
namespace ScreenshotConsole
{
class Program
{
static void Main(string[] args)
{
screenshot();
Console.WriteLine("Printescreened");
saveScreenshot();
Console.ReadLine();
}
static void screenshot()
{
SendKeys.SendWait("{PRTSC}");
}
static void saveScreenshot()
{
//string path;
//path = "%AppData%\\Sys32.png"; // collection of paths
//path = Environment.ExpandEnvironmentVariables(path);
if (Clipboard.ContainsImage() == true)
{
Image image = (Image)Clipboard.GetDataObject().GetData(DataFormats.Bitmap);
image.Save("image.jpeg", System.Drawing.Imaging.ImageFormat.Jpeg);
}
else
{
Console.WriteLine("Clipboard empty.");
}
}
}
}
Run Code Online (Sandbox Code Playgroud) 这是我在C#中的代码:一旦这个程序运行它很容易终止,我看不到它的输出,有人能告诉我这段代码有什么问题吗?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static int sum(int num1, int num2, int num3)
{
int total;
total = num1 + num2 + num3;
return total;
}
static void Main(string[] args)
{
Console.Write("\n\nFunction to calculate the sum of two numbers :\n");
Console.Write("--------------------------------------------------\n");
Console.Write("Enter a number1: ");
int n1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter a number2: ");
int n2 = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter a number3: ");
int n3 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nThe sum of three numbers …Run Code Online (Sandbox Code Playgroud)