编写三个构造函数 [英] writing three constructors

查看:69
本文介绍了编写三个构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Address类中应构造三个构造函数.我不太了解它的外观.下面是如何编写这些构造函数的说明.

In the Address class there are three constructors that shall be made​​. I do not quite understand what it should look like. Down below it says how to write these constructors.


  1. 当我刚接触C#时,有人可以帮我吗?
  2. 此要求是什么意思:"m_strErrMessage字段旨在包含最终错误.使用消息后应将其清空?.
  3. 为什么应该包含错误,这样做有什么好处?
  4. 有人可以帮助我吗? (请参阅列表项1.)

  1. Can someone help me as I am new to C#?
  2. What does this requirement mean: "The field m_strErrMessage is meant to contain eventual errors. It should be emptied after the message is used"?.
  3. Why should it contain errors and what would be the benefit from that?
  4. Can somenone please help me? (see list item 1.)



这是我应该做什么的说明.

我的分配摘录:



Here is the explanation of what I should do.

Excerpt from my assignement:

5.1 Fields: As in the Address class diagram. The field m_strErrMessage is
meant to contain eventual errors. It should be emptied after the message
is used.
5.2 Constructors:
5.2.1 Write three constructors as follows:
5.2.2 One default constructor in which you assign all instance
variables of the type string to string.Empty. This is to avoid
null-problem with strings.
5.2.3 One constructor with 4 parameters:
public Address(string street, string zip, string city, Countries country)
5.2.4 A constructor with 3 parameters, eliminating country from the above.



感谢您浪费我宝贵的时间来做我应该做的事情!



Thanks for letting me waste your time with stuff I should do!

推荐答案

转到此处 [ ^ ]



  1. 是.
  2. 这意味着需求的作者几乎不熟悉最佳软件设计实践,甚至不熟悉(好的)Microsoft命名约定. (另请参阅Griff的回答.)对您来说,您甚至无法想象您所问的读者并提供足够的信息.
  3. 通常情况下,您不应这样做;并且没有人会得到任何好处.
  4. 请参阅第1条.

  1. Yes.
  2. It means that the author of the requirements is hardly familiar with best software design practices and even with (good) Microsoft naming conventions. (See also the response by Griff.) As to you, you cannot even picture the reader of you question and provide sufficient portion of information.
  3. In general case, it should not; and nobody will get any benefits.
  4. See item 1.



至于任务中的项目,除非有人解释了代码的主要目标,否则它们是没有意义的.另外,您从未问过有关此部分的单个问题.

—SA



As to the items from your assignment, they make no sense unless one explains the main goal of the code. Also, you never asked a single question about this part.

—SA


如果您要张贴作业,至少要使其看起来像您自己尝试做某事!

我们不做您的作业:这是有原因的.在这里,您可以考虑自己被告知的内容,并尝试理解它.也可以在那里帮助您的导师识别您的弱点,并将更多的注意力放在补救措施上.

话虽如此,我将解释您的第一个查询,因为这与不了解任务而不是完成作业有关.

他的意思是,将向m_strErrMessage提供一条报告错误的消息-一旦处理了错误,或者(大概)报告了错误,则应将其清除.这通常是为了防止重复报告.

顺便说一句:对于C#中的命名约定,m_strErrMessage是不好的做法:"m_"前缀表示类的成员(C#名称中未使用),"str"表示变量数据类型(再次不使用)并且名称可能是ErrorMessage或errorMessage,具体取决于它是属性还是内部字段.

第二部分对构造函数进行重新定义非常容易:它详细说明了问题中您必须做的事情! :laugh:
If you are going to post your homework, at least try to make it look like you have attempted to do something yourself!

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Having said that, I will explain your first query, because that is related to not understanding the task, rather than doing your homework.

What he means is that the m_strErrMessage will be given a message to report an error - and this it should be cleared once either the error has been handled, or (presumably) once it has been reported. This is normally to prevent it being reported repeatedly.

BTW: m_strErrMessage is bad practice for naming conventions in C#: the "m_" prefix indicate a member of a class (which isn''t used in C# names), the "str" indicates the variable datatype (which again is not used) and the name should probably be either ErrorMessage or errorMessage depending on whether it is property or an internal field.

The second part regrading the constructors is pretty easy: it spells out what you have to do in the question in considerable detail! :laugh:


这篇关于编写三个构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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