asp.net中如何自定义返回类型

mengjun5200 2008-07-20 06:23:03
比如VS自带的可以(红色部分)
public int insertp(string username),现在我想自己写个别的public xxx insertp(string name),请问这个xxxx怎么写呢?
...全文
186 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
honghu3000 2008-07-21
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 findcaiyzh 的回复:]
class MyClass
{
public int memberInt
public string memberString
}

public MyClass insertp(string name)
{
}
[/Quote]

先自己定义一个类,然后写个方法,返回自定义的类的类型
hy_lihuan 2008-07-21
  • 打赏
  • 举报
回复
自己定义一个类,就可以返回这个类;最典型的例子:
public BasicCodeEntity GetModel(int ID)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select * from SBGL_BASIC_CODE ");
strSql.Append(" where ID=:ID");
OracleParameter[] parameters = {
new OracleParameter(":ID", OracleType.Number)
};
parameters[0].Value = ID;

BasicCodeEntity model = new BasicCodeEntity();
DataSet ds = ado.ExecuteSqlDataset(strSql.ToString(), parameters);
model.ID = ID;
if (ds.Tables[0].Rows.Count > 0)
{
model.BasicCodeType = ds.Tables[0].Rows[0]["BASIC_CODE_TYPE"].ToString();
return model;
}
else
{
return null;
}
}
ychangh 2008-07-21
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 findcaiyzh 的回复:]
class MyClass
{
public int memberInt
public string memberString
}

public MyClass insertp(string name)
{
}
[/Quote]
DarkNight 2008-07-21
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 wangpanli 的回复:]
参数是字符串类型,调用加引号:


C# code
protected void Page_Load(object sender, EventArgs e)
{
testr t = new testr();
t.test0("shijun");
Response.Write(t.test0("shijun"));
}
[/Quote]
我觉得10楼的说的对
mengjun5200 2008-07-21
  • 打赏
  • 举报
回复
谢谢各位了,终于明白了,感谢
PenleyWang 2008-07-21
  • 打赏
  • 举报
回复
参数是字符串类型,调用加引号:


protected void Page_Load(object sender, EventArgs e)
{
testr t = new testr();
t.test0("shijun");
Response.Write(t.test0("shijun"));
}
billclinton8 2008-07-21
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 wangpanli 的回复:]
自己定义的类型,可以是类、结构体、或枚举。要先定义,才能使用。

一、类
C# codepubliccalss MyClass
{
.....
}publicMyClass MyFunc()
{
CMyClass cls;
....returncls;
}

二、枚举
C# codepublicenumMyColor{
Red,
Green,
Blue
}publicMyColor MyFunc()
{
CMyColor clr=MyColor.Red;
....returnclr;
}
[/Quote]
PenleyWang 2008-07-21
  • 打赏
  • 举报
回复
自己定义的类型,可以是类、结构体、或枚举。要先定义,才能使用。

一、类

public calss MyClass
{
.....
}

public MyClass MyFunc()
{
CMyClass cls;
....
return cls;
}



二、枚举

public enum MyColor{
Red,
Green,
Blue
}

public MyColor MyFunc()
{
CMyColor clr = MyColor.Red;
....
return clr;
}

mengjun5200 2008-07-21
  • 打赏
  • 举报
回复
我新建了个类。。testr.cs
public class testr
{
public testr()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public string insertp;
public testr test0(string name)
{
string Name = name;
return Name;

}
}


可是我在前台调用public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
testr t = new testr();
t.test0(shijun);
Response.Write(t.test0(shijun));
}

}

说不能够转换类型,哪错了?
wh520pl 2008-07-21
  • 打赏
  • 举报
回复
上面的都够了

public enum OrderStatue{
NonProcess, //未处理
Processed, //处理过的
Cancled, //取消的
FaHuoZhong //发货中
}

class order
{
public OrderPayStat PayMentStats;
}
mengjun5200 2008-07-21
  • 打赏
  • 举报
回复
还有例子没,我还想看个。。。一个怕还不能够完全接受
宝_爸 2008-07-20
  • 打赏
  • 举报
回复
class MyClass
{
public int memberInt
public string memberString
}

public MyClass insertp(string name)
{
}

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧