小编Mak*_*kin的帖子

LINQ在选择枚举时排除空值

下面的数据只是样本数据

ID  BatchName       File
===========================
1   Batch1          null 
2   Batch2          "C:\File2_1.pdf"
2   Batch2          "C:\File2_2.pdf"
3   Batch3          "C:\File3_1.pdf"
3   Batch3          "C:\File3_2.pdf"
Run Code Online (Sandbox Code Playgroud)

然后我有一个代表上述数据的类

public class SourceBatch
{
   public int ID {get;set;}
   public string BatchName {get;set;}
   public string File {get;set;}
}
Run Code Online (Sandbox Code Playgroud)

我把它通过想组IDBatchName选择所有File该组中到列表中。为此,我有相应的课程

public class DestinationBatch
{
   public int ID {get;set;}
   public string BatchName {get;set;}
   public IEnumerable<string> Files {get;set;} // this is list of string
}
Run Code Online (Sandbox Code Playgroud)

下面是执行此操作的代码

IList<SourceBatch> list = GetSourceList();

var result = list.GroupBy(x => new
{ …
Run Code Online (Sandbox Code Playgroud)

c# linq

1
推荐指数
1
解决办法
993
查看次数

C#跳过部分代码

我被困了 - 代码的第一部分" // OPEN PRELOADING PAGE "由于某种原因不会执行,将被跳过.如果我评论其余的代码,只保留这部分,它就可以了.怎么了?

protected void Create_Order_Click(object sender, EventArgs e)
{

  // OPEN PRELOADING PAGE
  Response.Write("<script>");
  Response.Write("window.open('smth.aspx','_blank')");
  Response.Write("</script>");

  // DEFINE CONNECTION
  SqlConnection conn = new SqlConnection(ConfigurationManager
             .ConnectionStrings["SqlConnectionString"].ConnectionString);

  // OPEN CONNECTION
  conn.Open();

  // DEFINE FIRST SQL QUERY
  string insertOrder = "INSERT INTO Order_Connection (FK_User_ID) VALUES ('" + Session["User_ID"] + "')";

  string str = FileUpload1.FileName;
  FileUpload1.PostedFile.SaveAs(Server.MapPath(".") + "//upload//" + str);
  string path = "//xxx.cz/intranet/pages/upload/" + str.ToString();

  string insertOrder_Content = "INSERT INTO Order_Content (Uploaded_Photo, Issue_Description, Place_Of_Repair, Transfer_Method, Date_To_Bring, Date_To_Take) …
Run Code Online (Sandbox Code Playgroud)

c# asp.net

0
推荐指数
1
解决办法
199
查看次数

返回不工作

我不明白为什么我无法studentinformation从该功能访问getstudentinformation.这是代码:

static void Main(string[] args)
{
    getstudentinformation();
    string firstname = studentinformation[0];
}

static Array getstudentinformation()
{
    Console.WriteLine("enter the student's first name: ");
    string firstname = Console.ReadLine();
    Console.WriteLine("enter the student's last name");
    string lastname = Console.ReadLine();
    Console.WriteLine("enter student's gender");
    string gender = Console.ReadLine();
    string[] studentinformation = { firstname, lastname, gender };
    return studentinformation;
}
Run Code Online (Sandbox Code Playgroud)

Visual Studio无法识别数组,当我尝试构建代码时,存在无法识别学生信息的错误.

c# return

0
推荐指数
1
解决办法
465
查看次数

生成随机数 - 更高的值

我有这个:

int minValue = int.Parse(min.Text);
int maxValue = int.Parse(max.Text);
Random rnd = new Random();
int final = rnd.Next(minValue, maxValue);
result.Text = final.ToString("");
Run Code Online (Sandbox Code Playgroud)

我将把两个值(较低的值和较高的值)放到两个文本框中.这些值由用户输入.当我生成随机数时,在任何情况下都不会出现更高的值.例如,用户输入1和5.我重复生成一个数字,在任何情况下都不会出现数字5.它只显示1,或2,或3,或4,而不是5.为什么?

.net c# random

0
推荐指数
2
解决办法
101
查看次数

标签 统计

c# ×4

.net ×1

asp.net ×1

linq ×1

random ×1

return ×1