我有一些代碼正在工作,但它似乎只是一個關於如何操作的方式,想知道是否有人有任何想法如何整理一下ASP.Net獲取具有值的列,然後將它們相加,然後將它們分開
這裏是我的代碼
Dim TotalNumber As Double
Dim NumberFilled As String
NumberFilled = Nothing
For x = 0 To drCode2a.Tables(0).Columns.Count - 1
If Not drCode2a.Tables(0).Rows(0)(x).ToString() = "0" Then
NumberFilled += drCode2a.Tables(0).Rows(0)(x).ToString() & "-"
TotalNumber = TotalNumber + drCode2a.Tables(0).Rows(0)(x).ToString()
End If
Next
Dim delimiters As Char() = New Char() {"-"c}
Dim TotalNumberFilled As String() = NumberFilled.Split(delimiters, StringSplitOptions.RemoveEmptyEntries)
Dim AverageRating As Double = TotalNumber/TotalNumberFilled.Length
Response.Write(NumberFilled & "<br/>" & TotalNumber & "<br/>" & AverageRating)
基本上我的例子NumberFilled = "1-2-"
和TotalNumber = 3
和AverageRating = 1.5
這表明,兩列分別填寫,他們等於總爲3故平均值= 1.5
正如我所說的它的工作原理像它應該,但我想整理一下,如果可能的
感謝