本文介绍了如何编写一个可以将一个字母转换为整数的Linq语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在尝试编写一个linq语句,它会将成绩字母改为数字,这样我就可以计算出gpa。 任何人都可以告诉我下面的代码sinnpet有什么问题。 如何以及在哪里可以声明单词等级,以便我可以停止获取错误等级未声明? 私人 Sub btnDisplay_Click( sender As Object ,e As EventArgs) 句柄 btnDisplay.Click Dim Gpa As 字符串 =聚合CreditHours 在 CoursesDataSet.tblCourses 让 gradeValue = 如果(Gr ade = , 4 , 如果(Grade = B, 3 ,如果(等级= C, 2 ,如果(等级= D, 1 , 0 )))) 选择 CreditHours * gradeValue 成Sum() MessageBox.Show( GPa:& ; Gpa.ToString( C2), 大学课程,MessageBoxButtons.OK, MessageBoxIcon.Information) 结束 Sub 解决方案 你可以使用字符的ASCII码。 例如: dim myInt as integer = ASC(等级) 在这个示例中,myInt的A为65,B为66,依此类推。 但注意:大写和小写的ASCII代码不是同样的! 问候 拉尔夫 实际上,你在这里得到了答案: http://stackoverflow.com/questions/30034330/linq-statement-error/30035184 [ ^ ] I am trying to write a linq statement that will change the letter of a grade into a number so i can calculate gpa.Can anyone tell me what is wrong with the below code sinnpet.How and where can I declare the word grade so i can stop getting the error grade is not declared? Private Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles btnDisplay.Click Dim Gpa As String = Aggregate CreditHours In CoursesDataSet.tblCourses Let gradeValue = If(Grade = "A", 4, If(Grade = "B", 3, If(Grade = "C", 2, If(Grade = "D", 1, 0)))) Select CreditHours * gradeValue Into Sum() MessageBox.Show("GPa:" & Gpa.ToString("C2"), "College Courses", MessageBoxButtons.OK, MessageBoxIcon.Information) End Sub 解决方案 Hi,you could use the ASCII-Code of the Character.For Example :dim myInt as integer = ASC(Grade)In this Example myInt will have 65 for "A", 66 for "B" and so on.But Attention : the ASCII-Code for Uppercase and Lowercase is not the same !GreetingsRalfActually, you've got your answer here: http://stackoverflow.com/questions/30034330/linq-statement-error/30035184[^] 这篇关于如何编写一个可以将一个字母转换为整数的Linq语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-29 21:19