类用作方法中的变量或参数 [英] class use as a variable or parameter in method
本文介绍了类用作方法中的变量或参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是.net编程的新手.
我想知道当我创建一个像user这样的类,然后再创建一些其他类时,
我正在创建函数或方法的页面,我可以将该类用作变量或参数,如method is
公用字符串validate(User user)
{
}
我的课是
i am new in .net programming.
i want to know that when i create a class like user and then some other
page i am creating a function or method can i use that class as variable or parameter like method is
public string validate(User user)
{
}
while my class is
using System;
using System.Collections.Generic;
using System.Text;
namespace MailingList {
public class User {
private string _userName ;
private string _password;
private int _oid;
public User() {
_userName = string.Empty;
_password = string.Empty;
_oid = 0;
}
public string UserName {
get { return _userName; }
set { _userName = value; }
}
public int OID {
get { return _oid; }
set { _oid = value; }
}
public string Password {
get { return _password; }
set { _password = value; }
}
}
}
这意味着什么,如果有人理解我的问题请我解释一下,我将无法解释我想知道的事情.
谢谢
}
what is the mean may be i am unable to explain what i want to know if any body understand my prob plz explain me.
Thanks
推荐答案
您不要将类用作参数.您可以使用类类型作为参数类型,并使用类的实例作为参数.
简而言之,这很好.
You don''t use the class as a parameter. You use the class type as the parameter type and an instance of your class as the parameter.
In short, this is fine.
public string validate(User user)<br />
{<br />
<br />
}
User
是您的课程,user
是此类的实例.
User
is your class and user
is an instance of this class.
这篇关于类用作方法中的变量或参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文