我有一个问题,我必须在主要的应用程序方法中演示以下内容 [英] I have a problem where i have to demonstrate the following in main application method

查看:59
本文介绍了我有一个问题,我必须在主要的应用程序方法中演示以下内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

声明并初始化类

使用类属性重新分配至少两个类变量

进行两次类方法调用



我尝试过:



公共课骰子

{

private int topFace = 1;

private随机myRand = new Random();



public void Roll()

{

// ......

}

}

解决方案

你的Dice课程中没有属性 - 你的作业特别希望你使用两个。同样,你需要在你的类中声明两个公共方法,以便可以调用它们 - 你没有。



好​​的,我们看不到你的实际作业 - 我们不会为你做的,如果可以的话,你会自己学习更多东西。

但是房产的语法是

< pre lang =c#> private TypeOfProperty _PropertyName; // 支持商店
public TypeOfProperty PropertyName // Property
{
获取 {返回 _PropertyName; }
set {_PropertyName = value ; }
}

你已经知道如何声明和实现的方法。

所以你需要做的就是创建两个方法和两个属性。

然后在你的Main方法中,创建一个类的实例,使用setter,并调用方法。

它不应该花很长时间 - 这不是'很复杂!


Declare and initialize the class
Reassign at least two class variables using class properties
Make two class method calls

What I have tried:

public class Dice
{
private int topFace = 1;
private Random myRand = new Random();

public void Roll()
{
// ......
}
}

解决方案

There are no properties in your Dice class - and your homework specifically wants you to use two. Similarly, you need to declare two public methods in your class so they can be called - you don't have any.

OK, we can't see your actual homework - and we wouldn't do it for you if we could, you will learn a lot more by doing it yourself.
But the syntax for a property is

private TypeOfProperty _PropertyName; // Backing store
public TypeOfProperty PropertyName    // Property
   {
   get { return _PropertyName; }
   set { _PropertyName = value; }
   }

Methods you already know how to declare and implement.
So all you need to do is create two methods, and two properties.
Then in your Main method, create an instance of the class, use the setters, and call the methods.
It shouldn't take you very long - this isn't complicated!


这篇关于我有一个问题,我必须在主要的应用程序方法中演示以下内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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