请输入您要查询的百科知识:

 

词条 This
释义

单词

释义

音标

[]

词性及解释

pron. 这, 本

a. 这, 本

ad. 这么

例句

This ship docked this morning.

这条船是今天早上靠的码头。

.This new approach is

新方案有:

.A downpour this afternoon

下午有瓢泼大雨

.For this particular purpose

为某一特别目的

.Move this heavy box

把这重箱子挪动

Pecified by doing this

将某物挤成某形状、大小等

Person who does this

(使人感到)忧愁的,沮丧的

.Shop operating this system

现款自运商店(实行上述制度的商店)

.Wish this delay tolerate

望原谅我的延误。

.This work continues. This story goes on.

这项工作必须继续下去。

.

计算机语言

C#中的thi

C#中的保留字this仅限于在构造函数,类的方法和类的实例中使用。

* 在类的构造函数中出现的this作为一个值类型,它表示对正在构造的对象本身的引用

* 在类的方法中出现的this作为一个值类型,表示对调用该方法的对象的引用

* 在结构的构造函数中出现的this作为一个变量类型,表示对正在构造的结构的引用

* 在结构的方法中出现this作为一个变量类型,表示对调用该方法的结构的引用

* 被用来区分类成员及本地的成员

* 除此之外,其他地方使用this保留字都是不合法的。

一.this的常用用途:

1.限定被相似的名称隐藏的成员

eg:public Employee(string name, string alias)

{

this.name = name;

this.alias = alias;

}

2.将对象作为参数传递到其他方法

eg:CalcTax(this);

3.声明索引器

eg:public int this [int param]

{

get { return array[param]; }

set { array[param] = value; }

}

二.典型示例

在本例中,this 用于限定 Employee 类成员 name 和 alias,它们都被相似的名称隐藏。this 还用于将对象传递到属于其他类的方法 CalcTax。

// keywords_this.cs

// this example

using System;

class Employee

{

private string name;

private string alias;

private decimal salary = 3000.00m;

// Constructor:

public Employee(string name, string alias)

{

// Use this to qualify the fields, name and alias:

this.name = name;

this.alias = alias;

}

// Printing method:

public void printEmployee()

{

Console.WriteLine("Name: {0}\Alias: {1}", name, alias);

// Passing the object to the CalcTax method by using this:

Console.WriteLine("Taxes: {0:C}", Tax.CalcTax(this));

}

public decimal Salary

{

get { return salary; }

}

}

class Tax

{

public static decimal CalcTax(Employee E)

{

return 0.08m * E.Salary;

}

}

class MainClass

{

static void Main()

{

// Create objects:

Employee E1 = new Employee("John M. Trainer", "jtrainer");

// Display results:

E1.printEmployee();

}

}

输出:

Name: John M. Trainer

Alias: jtrainer

Taxes: $240.00

C++中的thi

this指针只能是非静态成员函数class, struct, 和 union类型中的指针访问,它指向被调函数中的对象。静态成员函数中没有this指针。

this

this->member-identifier

一.备注:

1.一个对象的this指针并不是这个对象自身的一部分;当一个非静态成员函数调用一个对象时,对象的地址就以隐藏参数的形式通过编译器传递给了函数。

eg:

myDate.setMonth(3);

也可以这样表达:

setMonth(&myDate,3);

2.对象的地址可以通过this指针在成员函数中传递。this在使用时大多时候都是隐式方式,这是合法的。尽管不必要,但在访问class的成员时请明确使用this指针。

eg:

void Date::setMonth( int mn )

{

month = mn; // These three statements

this->month = mn; // are equivalent

(*this).month = mn;

}

3.*this这种表达形式通常是用来在成员函数中返回当前对象。

eg:

return *this;

4.this指针有时候也用来防止自我引用。

eg:

if (&Object != this) {

// do not execute in cases of self-reference

二.典型示例

// this_pointer.cpp

// compile with: /EHsc

#include <iostream>

#include <string.h>

using namespace std;

class Buf

{

public:

Buf( char* szBuffer, size_t sizeOfBuffer );

Buf& operator=( const Buf & );

void Display() { cout << buffer << endl; }

private:

char* buffer;

size_t sizeOfBuffer;

};

Buf::Buf( char* szBuffer, size_t sizeOfBuffer )

{

sizeOfBuffer++; // account for a NULL terminator

buffer = new char[ sizeOfBuffer ];

if (buffer)

{

strcpy_s( buffer, sizeOfBuffer, szBuffer );

sizeOfBuffer = sizeOfBuffer;

}

}

Buf& Buf::operator=( const Buf &otherbuf )

{

if( &otherbuf != this )

{

if (buffer)

delete [] buffer;

sizeOfBuffer = strlen( otherbuf.buffer ) + 1;

buffer = new char[sizeOfBuffer];

strcpy_s( buffer, sizeOfBuffer, otherbuf.buffer );

}

return *this;

}

int main()

{

Buf myBuf( "my buffer", 10 );

Buf yourBuf( "your buffer", 12 );

// Display 'my buffer'

myBuf.Display();

// assignment opperator

myBuf = yourBuf;

// Display 'your buffer'

myBuf.Display();

}

输出:

my buffer

your buffer

AS3.0中的thi

this在一个类里面是指代类‘自己’,通过这个指向,可以访问类内部的属性、方法(在外部只能访问公用的)。this,在帧代码里,指向舞台,可以访问舞台的元素。

其他

烟名 THIS

产地 韩国

随便看

 

百科全书收录4421916条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。

 

Copyright © 2004-2023 Cnenc.net All Rights Reserved
更新时间:2025/2/27 4:47:28