我想从我试过的文本文件中读取数据,但它显示错误显示文件路径中的错误
string txtfile = File.ReadAllText("D:\Temp\textdata.txt");
string txtdata = File.ReadAllText("D:\Temp\textstrings.txt");
string txtpara = File.ReadAllText("D:\Temp\textlines.txt");
Console.WriteLine(txtfile);
Console.WriteLine("\n");
Console.WriteLine("\n");
Console.WriteLine(txtpara);
Console.WriteLine("\n");
Console.WriteLine("\n");
Console.WriteLine("\n");
Console.WriteLine(txtdata);
Run Code Online (Sandbox Code Playgroud)
我的文件已保存 d:\temp\textdata.txt
有人能告诉我吗?
好吧,我坚持使用未分配的局部变量.我首先声明我的变量并创建我的字典.
在我的代码下面:
string berichtAantalMunten;
double[] munten = { 2,1,0.50,0.20,0.10,0.05};
Dictionary<double, int> aantalMunten = new Dictionary<double, int>();
int muntenTeller = 0;
double bedragTerug = totaalIngeworpen - prijsDrankje;
foreach (double munt in munten){
double tijdelijkIngeworpen = totaalIngeworpen - munt;
if (tijdelijkIngeworpen >= 0)
{
muntenTeller++;
aantalMunten.Add(munt, muntenTeller);
totaalIngeworpen = tijdelijkIngeworpen;
}
}
if (aantalMunten.ContainsKey(2))
{
berichtAantalMunten = aantalMunten[2].ToString() + " x € 2,00\n";
}
if (aantalMunten.ContainsKey(1))
{
berichtAantalMunten += aantalMunten[1].ToString() + " x € 1,00\n";
}
Run Code Online (Sandbox Code Playgroud) 我的C#代码一直给我一个错误的转换结果.据我所知,转换公式是正确的,但它仍然显示错误的结果.
例如:70°F给我12,777777°C.你能检查一下我的代码吗?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Temperature
{
class Program
{
class Temperature
{
public double temp;
public void Convert(double value)
{
double tEmp;
tEmp = (value - 32) / 1.8;
Console.WriteLine("The temperature in °C is :" + tEmp);
Console.ReadKey();
}
}
static void Main(string[] args)
{
double f;
Temperature c = new Temperature();
f = Console.Read();
c.Convert(f);
}
}
}
Run Code Online (Sandbox Code Playgroud) 当我29/07/1990在文本框中书写时,此代码似乎不起作用.它总是转到else语句.
string date = tbDate.Text;
DateTime Test;
if (DateTime.TryParseExact(date, "MM/dd/yyyy", null, DateTimeStyles.None, out Test) == true) {
Console.WriteLine("Date OK");
} else {
Console.WriteLine("Date Not OK");
}
Run Code Online (Sandbox Code Playgroud) 这是我的代码:
float SmoothNoise(float x, float y)
{
float fractX = x - (int)x;
float fractY = y - (int)y;
float x1 = ((int)x + noiseWidth) % noiseWidth;
float y1 = ((int)y + noiseHeight) % noiseHeight;
float x2 = ((int)x + noiseWidth - 1f) % noiseWidth;
float y2 = ((int)y + noiseHeight - 1f) % noiseHeight;
float value = 0f;
value += fractX * fractY * noise[x1, y1];
value += fractX * (1f - fractY) * noise[x1, y2];
value += (1f …Run Code Online (Sandbox Code Playgroud) 我有一个临时表#allocations,它有以下字段
DAllocationId DAllocationName FundCode DSplitTotal DDisabled DistAlloc AAllocationId AAllocationName ASplitTotal ADisabled
Run Code Online (Sandbox Code Playgroud)
我有另一个表TRAN_POST_PTN,它还包含这些列以及其他列.因此对于asplit id和dsplit id,我们只有相同的列名,即TRAN_POST_PTN中的"发布号码".
我需要做的是在我的分配表中插入来自TRAN_POST_PTN的所有行
posting_number is not in (select DAllocationId from #allocations)
and posting_number not in (select AAllocationId from #allocations)
Run Code Online (Sandbox Code Playgroud)
我不想在这里使用Not.
有人可以建议我更好的方式来编写这个查询.我尝试使用union编写它,但这不起作用.
我得到错误" INCORRECT SYNTAX NEAR''.
这是我的代码:
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Mr\Documents\Student.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.Parameters.Clear();
cmd.CommandText = "insert into tblHesabdary(Shahriye Koll,Pardakhty,Mablagh,Naghdy - Shomare Fish,Albaghy,Name,Family)values(@SK,@P,@M,@NSF,@A,@N,@F)";
cmd.Parameters.AddWithValue("@SK", shahriye_KollTextBox.Text);
cmd.Parameters.AddWithValue("@P", pardakhtyTextBox.Text);
cmd.Parameters.AddWithValue("@M", mablaghTextBox.Text);
cmd.Parameters.AddWithValue("@NSF", naghdy___Shomare_FishTextBox.Text);
cmd.Parameters.AddWithValue("@A", albaghyTextBox.Text);
cmd.Parameters.AddWithValue("@N", nameTextBox.Text);
cmd.Parameters.AddWithValue("@F", familyTextBox.Text);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("jj");
Run Code Online (Sandbox Code Playgroud)
我的数据库是SQL Server Express.
我一直很难将我的变量值从表单1传输到我的form2.问题是我想在Form2加载时在Form2 textBoxes中显示我在Form1中初始化的结果(当我单击相应的按钮时,它会显示一个ShowDialog()).
我的问题是结果不在我的Form2中传输,给我的所有变量一个0值.
这是我在表格中的内容:
//Variables in my Form 1
public partial class Form1 : Form
{
public static double VAR_1 = 1;
public static double VAR_2 = 2;
public static double VAR_3 = 3;
//Here I put all my textBoxes and other methods of the class
}
//Variables in my Form 2
public partial class Form2 : Form
{
private void Form2_Load(object sender, EventArgs e)
{
this.textBox1.Text = Form1.VAR_1.ToString();
this.textBox2.Text = Form1.VAR_2.ToString();
this.textBox3.Text = Form1.VAR_3.ToString();
}
}
Run Code Online (Sandbox Code Playgroud)