classA a = new classA(){data = 5}; [英] classA a = new classA() { data = 5 };

查看:241
本文介绍了classA a = new classA(){data = 5};的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个程序的输出是什么?



What is the output of this program?

classA a = new classA() { data = 5 };

classA b = a;

b.data = 10;

Console.WriteLine(a.data);

推荐答案

运行它并找出答案!我们不是来为您做测试!
Run it and find out! we are not here to do your testing for you!


10





(我有编译器)。


嗨bado,


我可以问一个反问题:我可以猜测它会在没有运行的情况下打印出来,即使它不是程序只是一段代码 - 这会对你有所帮助吗无论如何?另一方面,这段代码没有独特的含义(我假设classA是一个引用类型,但是谁知道你可能做过类似的事情:



struct classA {}



假设你是学生/学习者我会说试着理解这个例子给你看的是什么(指针,参考,别名)。任何具体的理解问题? - >提出具体问题....



亲切的问候



Johannes
Hi bado,

May I ask a counter question: I can guess what this will print without running it, even if it's not a "Program" just a snippet of code - will this help you in any way? On the other hand this code has no unique meaning (I'd assume classA is a reference type, but who knows maybe you did something like that:

struct classA { }

Assuming you are a studend/learner I'd say try to understand what this example is showing you (pointers, references, alias). Any specific understanding problems? -> Ask a specific question....

Kind regards

Johannes


这篇关于classA a = new classA(){data = 5};的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆