你的位置:首页 > 软件开发 > ASP.net > C#——this关键字(2)(含求助贴)

C#——this关键字(2)(含求助贴)

发布时间:2016-12-03 19:00:36
这次来看一看this关键字的第二个用法:将对象作为参数传递到其他方法---------------------------------------------------------------------------------- 1 using System; 2 using ...

这次来看一看this关键字的第二个用法:将对象作为参数传递到其他方法

----------------------------------------------------------------------------------

 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6  7 //我们假设要把一个学生的成绩按70%折算 8  9 namespace @this10 {11   class Program12   {13     static void Main(get='_blank'>string[] args)14     {15       Student student = new Student();16       student.GetMessage("Mark");17       student.PrintScore ();18     }19   }20 21   class Student22   {23     public string Name { get; set; }24     private int Score = 100;25 26     public void GetMessage(string Name)27     {28       //这个this用法属于第一种:限定被相似的名称隐藏的成员29          this.Name = Name;30     }31 32     public int score33     {34       get { return Score; }35     }36 37     public void PrintScore()38     {39       Console.WriteLine("My Name Is {0}, My Score Is {1}",Name,score );40       Console.WriteLine("How many points after converting? ");41       Console.WriteLine("The Converted Score Is {0}",Convert .ConvertedScore(this));//注意:这里要用this传参数了42     }43   }44 45   class Convert46   {47     public static int ConvertedScore(Student stu)//折算分数48     {49       return (int)(0.7 * stu.score);//强制类型转换一下50     }51   }52   53 }

 

海外公司注册、海外银行开户、跨境平台代入驻、VAT、EPR等知识和在线办理:https://www.xlkjsw.com

原标题:C#——this关键字(2)(含求助贴)

关键词:C#

C#
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录