以前用VB,现在开始学C#,菜鸟问题请大家不要见笑。
private string test(string a)
{
test="hello:" + a;
}
然后调用它
string a="name";
string b=test(a);
我原指望b能得到 hello: name ,但提示出错,说在不带括号的情况下引用了......
在VB 中类似的写法是可以得到结果的,我不知在C# 中该怎么写?
private string test(string a)
{
test="hello:" + a;
}
然后调用它
string a="name";
string b=test(a);
我原指望b能得到 hello: name ,但提示出错,说在不带括号的情况下引用了......
在VB 中类似的写法是可以得到结果的,我不知在C# 中该怎么写?
解决方案 »
- 求助,IIS7.5中使用.NET 4.0中Url路由功能的配置问题。
- 请问:jQuery如何去掉td的某些属性?
- session 和Cookie有什么关系么?
- 看過《圣殿祭司的ASP.NET 2.0开发详解--使用C#》或者《asp.net 2.0 高級編程4》的進來看看~~~
- Container.DataItem问题
- 用.net表示某一日期-30天,要求是最终结果是日期型
- asp.net与Liunx
- 发送邮件的问题,编译报错!!!!
- 在ASP.NET里面怎么把数据导出为WORD的形式!!!
- 大家觉得这本书值得买吗!?<<.net系统构架与开发>>!买过的兄弟说说怎么样!?
- 请问如何让在DataGrid 中的 RadioButton实现单选
- 有谁用过asp.net forum2.0的框架开发过项目,我想问问这个框架适合一个普通网站开发吗?
{
return "hello:" + a;
}
{
return test="hello:" + a;
}
你只有计算结果,而没有返回,加个RETURN 即可
{
test="hello:" + a;
}
在C#中叫做方法。string 是这个方法的返回类型。要想得到返回值就必须要使用return.
private string test(string a)
{
return "hello:" + a;
}
按上面这样写就可以得到你想要的结果了。
{
test="hello:" + a;
}
string test;
string a="name";
b=test(a);
此时,test已经被赋值变成了:test="hello: name ";
Response.Write(test);
{
strin test;
test = "hello:"+a;
return test;
}