C#中的引用和对象
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了C#中的引用和对象,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1358字,纯文字阅读大概需要2分钟。
内容图文
![C#中的引用和对象](/upload/InfoBanner/zyjiaocheng/681/ec1fcee0b6c2471abcbbf2f105181c31.jpg)
我目前正在写作业.我在如何注释应用程序的不同部分方面遇到了麻烦.
我需要从文件中读取数据,因此我使用StreamReader类.
当我写这个
StreamReader reader;
我很难定义我刚刚做了什么. Rob Miles撰写的C#Yellow Book定义了非常相似的代码
Account RobsAccount;
What you actually get when the program obeys that line is the creation of a reference
called RobsAccount.
他以行李牌为类比
You can think of them as a bit like a luggage tag, in that they can be tied to
something with a piece of rope. If you have the tag you can then follow the rope to the
object it is tied to.
当Rob Miles稍后再写时
RobsAccount = new Account();
他形容为
(…)creating an instance of the class and then connecting our tag
to it.
RobsAccount = new Account();
与我的情况类似,我只写
reader = new StreamReader(file, Encoding.Default);
在阅读了几本关于C#的不同书籍之后,我仍然无法自信地评论所谓的内容.他们似乎使用了不同的名称和不同的类比.
所以我的问题是:
什么是对此的适当评论
StreamReader reader;
对此有什么合适的评论
reader = new StreamReader(file, Encoding.Default);
我的编程老师说,当你写
StreamReader reader;
您正在使用名称reader创建类型为StreamReader的变量.该变量实际上是指向通过写操作创建的对象的指针(因此,引用)
new StreamReader(file, Encoding.Default);
这是描述它的正确方法吗?
解决方法:
StreamReader reader;
这是变量声明.
reader = new StreamReader(file, Encoding.Default);
在这里,您将使用StreamReader类的对象实例化变量“ reader”.
内容总结
以上是互联网集市为您收集整理的C#中的引用和对象全部内容,希望文章能够帮你解决C#中的引用和对象所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。