我正在阅读.Net书籍,在其中一个代码示例中,有一个带有此字段的类定义:
private DateTime? startdate
Run Code Online (Sandbox Code Playgroud)
什么DateTime?意思?
我想编写一个 WCF Web 服务,可以通过线路将文件发送到客户端。所以我有一个发送流响应的设置。这是我在客户端的代码:
private void button1_Click(object sender, EventArgs e)
{
string filename = System.Environment.CurrentDirectory + "\\Picture.jpg";
if (File.Exists(filename))
File.Delete(filename);
StreamServiceClient client = new StreamServiceClient();
int length = 256;
byte[] buffer = new byte[length];
FileStream sink = new FileStream(filename, FileMode.CreateNew, FileAccess.Write);
Stream source = client.GetData();
int bytesRead;
while ((bytesRead = source.Read(buffer,0,length))> 0)
{
sink.Write(buffer,0,length);
}
source.Close();
sink.Close();
MessageBox.Show("All done");
}
Run Code Online (Sandbox Code Playgroud)
一切都进展顺利,没有错误或异常。问题是,当我打开正在传输的 .jpg 文件时,该文件被报告为“已损坏或太大”。
我究竟做错了什么?
在服务器端,这是发送文件的方法。
public Stream GetData()
{
string filename = Environment.CurrentDirectory+"\\Chrysanthemum.jpg";
FileStream myfile = File.OpenRead(filename);
return myfile;
} …Run Code Online (Sandbox Code Playgroud) 目前最好的做法是使用Environment.NewLine在你的代码,好了,开始一个新行.我希望能够在我的代码中使用别名或重载运算符,以便更简洁.而不是这个:
MessageBox.Show("My first line here" + Environment.NewLine + "My second line here");
Run Code Online (Sandbox Code Playgroud)
我想要这样的东西:
MessageBox.Show("My first line here" + NL + "My second line here");
Run Code Online (Sandbox Code Playgroud)
如何轻松地将其设置为IDE设置或整个项目/命名空间?
别名或重载运算符是想到的,但不知道是否有做一个全球性的别名比Environment.NewLine更简洁的一个很好的方式,我从来没有做过一个重载的操作,所以不熟悉来龙去脉.
在DataGridView的选定行后面检索Linq实体的优雅/正确方法是什么?我在表单Load事件中填充我的DataGridView:
this.Database = new MyAppDataContext();
var userList = from c in this.Database.Users
orderby c.LastName
select c;
this.gridUserList.DataSource = userList;
Run Code Online (Sandbox Code Playgroud)
然后,在我正在执行此操作的表单的DoubleClick事件中:
int userPK = Convert.ToInt32(this.gridUserList.CurrentRow.Cells["colUserPK"].Value);
var user = (from c in this.Database.Users
where c.UserPK == userPK select c).First() ;
//Do something with user object
Run Code Online (Sandbox Code Playgroud)
似乎应该有一种更优雅的方式来获取双击的用户行.
c# ×4
.net ×2
datagridview ×1
datetime ×1
linq-to-sql ×1
nullable ×1
stream ×1
streaming ×1
syntax ×1
wcf ×1