this 用法

gw0703 2009-12-14 04:30:25

求构造函数中this 用法

功能和例子

thanks...
...全文
108 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
gw0703 2009-12-14
  • 打赏
  • 举报
回复
就是在看。。给看不转。。。

没例子。看不是很明白。。。。
vrhero 2009-12-14
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 gw0703 的回复:]
我要这种:

class baseClass
{ public baseClass(int a)


}

class driveredClass:baseClass
{
  public driveredClass:this(int a)
}


这种是什么意思:this
[/Quote]
构造函数重载...去看MSDN...
gw0703 2009-12-14
  • 打赏
  • 举报
回复
我要这种:

class baseClass
{ public baseClass(int a)


}

class driveredClass:baseClass
{
public driveredClass:this(int a)
}


这种是什么意思:this
wangkuang5 2009-12-14
  • 打赏
  • 举报
回复

class TA_INIDocument
{

public TA_INIDocument(){}
public TA_INIDocument(string path):this(){
//ini文件读路径,然后ReadAllText( ),等等其它操作,构造函数在原有基础上重载

}

#region TA_INIDocument
Dictionary<string, System.Collections.Specialized.NameValueCollection> data =
new Dictionary<string, NameValueCollection>();
static readonly System.Text.RegularExpressions.Regex regRemoveEmptyLines =
new System.Text.RegularExpressions.Regex
(
@"(\s*;[\d\D]*?\r?\n)+|\r?\n(\s*\r?\n)*",
System.Text.RegularExpressions.RegexOptions.Multiline | System.Text.RegularExpressions.RegexOptions.Compiled
);

static readonly System.Text.RegularExpressions.Regex regParseIniData =
new System.Text.RegularExpressions.Regex
(
@"
(?<IsSection>
^\s*\[(?<SectionName>[^\]]+)?\]\s*$
)
|
(?<IsKeyValue>
^\s*(?<Key>[^(\s*\=\s*)]+)?\s*\=\s*(?<Value>[\d\D]*)$
)",
System.Text.RegularExpressions.RegexOptions.Compiled |
System.Text.RegularExpressions.RegexOptions.IgnoreCase |
System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace
);
public void ReadAllText( )
{
string fullpath = Application.StartupPath + "\\" + EMPSystemConfigurations.INI_CFG_PATH;
data.Clear();
string lastSection = string.Empty;
data.Add(lastSection, new NameValueCollection());

string iniData;
using (StreamReader reader = new StreamReader(fullpath))
{
iniData = reader.ReadToEnd();
}

iniData = regRemoveEmptyLines.Replace(iniData, "\n");

string[] lines = iniData.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);

foreach (string s in lines)
{
Match m = regParseIniData.Match(s);
if (m.Success)
{
if (m.Groups["IsSection"].Length > 0)
{
string sName =m.Groups["SectionName"].Value.ToLowerInvariant();
if (lastSection != sName)
{
lastSection = sName;
if (!data.ContainsKey(sName))
{
data.Add(sName, new NameValueCollection());
}
}
}
else if (m.Groups["IsKeyValue"].Length > 0)
{
data[lastSection].Add(m.Groups["Key"].Value,m.Groups["Value"].Value);
}
}
}

}
public NameValueCollection this[string section]
{
get
{
section = section.ToLowerInvariant();
if (!data.ContainsKey(section))
data.Add(section, new NameValueCollection());
return data[section];
}
}


//this当做索引器,直接取值
public string this[string section, string key]
{
get
{
return this[section][key];
}
//set
//{
// this[section][key] = value;
//}
}
#endregion
}


ztenv 2009-12-14
  • 打赏
  • 举报
回复
构造函数中可以不用也可以用:
class aa
{
int no;

public aa(int no){this.no=no;}

}
longhair9711 2009-12-14
  • 打赏
  • 举报
回复
class A
{
private string str1;
public A(string str2)
{
this.str1 = str2;
}
}
liherun 2009-12-14
  • 打赏
  • 举报
回复
class a
{
private canshu;
public a(string canshu)
this.canshu=canshu;
}
this.canshu中的this表示类本身
this.canshu就是类的成员 指的是类的属性
canshu就是构造函数中的参数了

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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