列表问题(整数) [英] Problem with List (of Integer)

查看:65
本文介绍了列表问题(整数)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我是泛型类型的新手,我制作了一个返回整数列表的函数.

hello

I am new with generic types.I have made a function which returns list of integers.

Private Function calculate(ByVal eid As String, ByVal fn As String, ByVal from As String) As List(Of Integer)

Dim Sol As New List(Of Integer)

        Sol.Add(CountNoOfInstallment)
        Sol.Add(NoOfInstallment)
        Sol.Add(InstallmentAmount)
        Sol.Add(FinalAmount)

  End Function



这是我在此函数中计算出的所有4个值.我想知道这是正确的方法吗?

现在我在pageload上调用此函数



here all the 4 values i have calculated inside this function. I want to know is this the the right way to do it ??

now i am calling this function on pageload

Dim MyList As List(Of Integer) = calculate(Request.QueryString("eid").ToString(), Request.QueryString("fn").ToString(), Year)

 Dim CountNoOFInstallment As Int32 = MyList.Item(0)
                Dim NoOfInstallment As Int32 = MyList.Item(1)



当我使用断点MyList时,它什么也没显示,还有错误,说对象引用未设置为对象实例.我知道代码有很多错误.请告诉我哪里出了问题以及如何纠正.我用谷歌搜索,但听不懂,然后我的朋友向我建议该网站寻求帮助.



when i used breakpoints MyList shows nothing in it also there is error saying object refrence not set to an instance of object. I know there are many things wrong with the code. please tell me what is wrong and how can it be corrected. I googled but wasn''t able to understand then my friend suggested me this website to ask help for.

推荐答案

我猜
Return

语句.

请在

statement is missing from the Function calculate.

Please include the following line before the

End Function


Return Sol



所以整个代码看起来像是...:



So the overall code will look like... :

Private Function calculate(ByVal eid As String, ByVal fn As String, ByVal from As String) As List(Of Integer)
'Your calculations here

Dim Sol As New List(Of Integer)
Sol.Add(CountNoOfInstallment)
Sol.Add(NoOfInstallment)
Sol.Add(InstallmentAmount)
Sol.Add(FinalAmount)

Return Sol

End Function


是的,很多事情是错误的,但主要的错误是没有什么是清楚的.下次,尝试创建一个非常简短但完整的代码示例,以解决一个特定的孤立问题并提出一个问题(但在许多情况下,它将帮助您自己找到解决方案).

让我们看看:
方法calculate接受两个代码中未使用的字符串.为什么需要这两个参数?现在,您不显示CountNoOfInstallment, NoOfInstallment, InstallmentAmount, FinalAmount的来源吗?不是来自参数.它们必须来自某些外部环境.他们可能是宣告阶级的成员.如果不显示其声明,为什么要显示此代码.

但是主要的问题是:您不返回任何内容(它不应该编译).您会看到,您实例化了Sol(帮自己一个忙,不要在变量名中使用缩写),添加四个元素,什么也不返回.此操作的结果将丢失,并最终被垃圾回收,因为您只需将其保留为无法访问(
Yes, many things are wrong, but major wrong thing is that nothing is clear. Next time, try to create a very short but complete code sample for the sole purpose of addressing a particular isolated problem and asking a question (but in many cases it will help you to find the solution by yourself).

Let''s see:
The method calculate accepts two strings which are not used in its code. Why would you need those two parameters? Now, you don''t show where CountNoOfInstallment, NoOfInstallment, InstallmentAmount, FinalAmount come from? Not from parameters. They must come from some external context; they could be the members of declaring class. Why showing this code if you don''t show their declaration.

But the main problem is: you do not return anything (it should not compile). You see, you instantiate Sol (do yourself a big favor, never use abbreviations in variable names), add four elements and just return nothing. The result of this operation will be lost and eventually garbage-collected because you simply leave it unreachable (http://en.wikipedia.org/wiki/Garbage_collection_%28computer_science%29#Reachability_of_an_object[^]). Return the instance of the list you create. That''s it.

—SA


这篇关于列表问题(整数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆