是“类型",但像“变量"一样使用 [英] is a 'Type' but is used like a 'Variable'

查看:77
本文介绍了是“类型",但像“变量"一样使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我是C#的新手,并且遇到了一些语法问题.下面的代码行将引发此错误"...是'Type',但其用法类似于'Variable'

I'm new to C# and am having some syntax issues. The following line of code is throwing this error "... is a 'Type' but is used like a 'Variable'

返回 LoanSubAccount(AddSubAccount( LoanSubAccount ()));

我确定是否分配了AddSubAccount( new LoanSubAccount ());到一个变量并返回它,那将起作用.我不明白的是为什么我拥有的东西不起作用?

I'm sure if I assigned AddSubAccount(new LoanSubAccount()); to a variable and returned it, that would work. What I don't understand is why what I have doesn't work?

谢谢

普雷斯顿

< SNIPPET>

私有 SubAccount AddSubAccount( SubAccount 帐户){

private SubAccount AddSubAccount(SubAccount Account) {

SubAccountID = GetNextSubAccountNumber();

SubAccounts.Add(SubAccountID,Account);

返回 GetSubAccount(SubAccountID);

return GetSubAccount(SubAccountID);

}

LoanSubAccount AddLoanAccount(){

LoanSubAccount AddLoanAccount() {

返回 LoanSubAccount(AddSubAccount( LoanSubAccount ()));

return LoanSubAccount(AddSubAccount(new LoanSubAccount()));

}

推荐答案

您好,

我相信您收到错误的原因是因为您实际上并未实例化 LoanSubAccount AddLoanAccount()

LoanSubAccount AddLoanAccount()
{
返回 LoanSubAccount(AddSubAccount( LoanSubAccount ()));
}

Hi there,

I believe that the reason you are getting the error you are getting is because you are not actually instantiating the LoanSubAccount object that you are trying to return in the AddLoanAccount() function.

I believe that if you change your function to something like:

LoanSubAccount AddLoanAccount()
{
    return new LoanSubAccount(AddSubAccount(new LoanSubAccount()));
}


这篇关于是“类型",但像“变量"一样使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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