简体   繁体   English

如何计算 class 中每个科目学生的 position?

[英]how to calculate the position of students in each subject in a class?

ok to be more lucid.确定更清楚。 what i actually mean is this i have a datagrid with defferent columns such as Id column, firstname, and columns of deferent subjects below is the sample:我实际上的意思是我有一个数据网格,其中包含不同的列,例如 Id 列、名字和不同主题的列,下面是示例:

when each row from the sample datagrid is selected the all the scores for each subject column is shown in the textbox1. when each row from the sample datagrid is selected the all the scores for each subject column is shown in the textbox1. like this: sample before click event像这样:点击事件前的样本

and when the button1 event is clicked with code below:并且当使用以下代码单击 button1 事件时:

 foreach(int mark in txtresult.ToString())
        {
            if (mark < 40)
            {
                string[] parts = txtresults.Text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                int[] numbers = parts.Select(p => int.Parse(p)).ToArray();
                **int maximum = numbers.Max();**
                int position = Array.IndexOf(numbers, maximum);
                parts[position] = "1".ToString();
                txtresults.Text = string.Join(" ", parts);
            }
            else if(mark >=40 && <50)
            {
                m="2th" position etc... within the above block of code
            }

sample after button click event按钮单击事件后的示例

the score for each subject should be ranked according to specified range "if(mark <40)" but it is rather ranking only the Max();每个科目的分数应该根据指定范围“if(mark <40)”进行排名,但它只是排名Max(); values in the textbox and not the small values within the textbox also.文本框中的值,而不是文本框中的小值。

so my question is: how can i grade each student within the datagrid Like in: column English i want to be able to rank the highest student with 1st, and next highest with 2nd... etc. and wherever the loop meets similar score in the text box will have similar position and continue ranking.所以我的问题是:我如何对数据网格中的每个学生进行评分就像在:列英语中,我希望能够将最高的学生排名第一,第二高的学生排名第二……等等,以及循环遇到类似分数的地方文本框将有类似的 position 并继续排名。 until all scores of each student are ranked;直到每个学生的所有分数都被排名; (eg. Eng =56, 78, 89, 76, 89.. from this 89 => 1st; 89 =>1st; 78 => 3rd; 76 =>4th position; & 56=>5th position;) (例如,Eng =56, 78, 89, 76, 89.. 从这个 89 => 1st; 89 =>1st; 78 => 3rd; 76 =>4th position; & 56=> 5th Z4757FE07FD492A8BE0EA6A760D683)

You can use LINQ to group items of a collection.您可以使用 LINQ 对集合的项目进行分组。

The following example creates three groups:以下示例创建三个组:
"Low", "Mid", "High" using a rule for values使用值规则的“低”、“中”、“高”
n < 10 , n >= 10 && n < 100 , n >= 100 : n < 10n >= 10 && n < 100n >= 100

var numericString = "1 2 12 15 123 757";
var numberGroups = numericString
  .Split(' ', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries)
  .Select(numericString => int.Parse(numericString))
  .GroupBy(number => number < 10
    ? "Low" 
    : number < 100 
      ? "Mid" 
      : "High");

// Access the groups
foreach (IGrouping<string, int> numberGroup in numberGroups)
{
  string groupName = numberGroup.Key; // E.g. "High"
  IEnumerable<int> groupValues = numberGroup; // 123, 757
}

And to group equal values:并将相等的值分组:

var numericString = "100 20 12 100 20 20 48 100";
var numberGroups = numericString
  .Split(' ', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries)
  .Select(numericString => int.Parse(numericString))
  .GroupBy(number => number);

// Access the groups
foreach (IGrouping<int, int> numberGroup in numberGroups)
{
  int groupName = numberGroup.Key; // E.g. 100
  List<int> groupValues = numberGroup.ToList(); // 100, 100, 100
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何计算学生的平均绩点(GPA) - How to calculate the grade point average(GPA) of students 如何找到该科目,计算每个学生在所有其他科目中的总分 C# - How to find that subject, calculate the total marks of each student in all the other subjects C# LINQ方法计算有多少学生至少有一个科目的最高成绩 - LINQ method to count how many students have at least one greatest grade in subject 如何计算屏幕位置 - How calculate screen position 列出学生的课程表 - List Class Schedule for Students 如何根据屏幕位置计算矩阵中的位置 - How to calculate the position in matrix based on screen position 如何根据总数计算学生排名,如果重复总次数两次,则排名应相同 - How to Calculate students Rank based on the Total, If the Total amount repeated twice then the rank should be same 如何遍历和比较学生班级和课程表班级,如果它们相同,则将它们显示在 html 页面上 - how would iterate through and compare the students class and the class schedule class and if they are the same then display them on the html page 如何计算/定位用户控件在占位符上的当前位置? - How to calculate/target usercontrol current position on placeholder? 射击敌人,如何计算弹丸的下一个位置 - Shooting the enemy, how to calculate the next position of the projectile
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM