我想知道,如果我使用额外的使用语句是否重要,是否需要更多时间来编译,是否会导致任何不良?谢谢.
好吧,所以我正在学习继承,我做了一些事情,这是代码:
class array
{
int [] arr;
public array(int[] arr)
{
this.arr = arr;
}
public int Biggest()
{
return arr.Max();
}
public int Min()
{
return arr.Min();
}
public int SumArr()
{
return arr.Sum();
}
}
class array2 : array
{
public array2(int [] arr):base(arr)
{
}
public double Average()
{
return
}
}
Run Code Online (Sandbox Code Playgroud)
现在,在派生类中我需要得到数组的平均值而我不能做arr.Average()错误说:Error 1 'ConsoleApplication1.array.arr' is inaccessible due to its protection level C:\Users\x\AppData\Local\Temporary Projects\ConsoleApplication1\Program.cs 35 20 ConsoleApplication1
任何人都可以告诉我我做错了什么?谢谢你的帮助!
好吧,所以这是练习:你必须定义三个类.一个名为MyNum的类,它包含int类型的变量.第二个类叫做MyString,将派生自MyNum并包含字符串.第三类调用MyType并返回MyNum类型的变量.每个类都将设置为构造函数和名为Show的虚函数.MyType的构造函数接收MyNum变量,而Show of MyType函数将运行MyNum的Show函数.现在,您需要设置两个MyType类型的对象并初始化它们.一旦对象类型为MyNum,则一次为MyString类型的对象.
这是代码:
class MyNum
{
protected int num;
public MyNum(int num)
{
this.num = num;
}
public virtual void Show()
{
Console.WriteLine("The number is : " + num);
}
}
class MyString : MyNum
{
string str;
public MyString(string str)
{
this.str= str;
}
}
class MyType : MyNum
{
MyNum num2;
public MyType(MyNum num)
{
this.num2 = num;
}
public override void Show()
{
base.Show();
}
}
class Program
{
static void Main(string[] args)
{
}
} …Run Code Online (Sandbox Code Playgroud) 我有以下练习:定义一个名为circle的类,它接受point类型的对象,并计算它们与圆心的距离.如果该点在圆圈之外,则应发送异常通知.
这是我的代码:
class Point
{
protected int x,y;
public Point(int x,int y)
{
this.x = x;
this.y = y;
}
}
class Circle : Point
{
public Circle(Point p,int radius):base(3,5)
{
}
}
class Program
{
static void Main(string[] args)
{
}
}
Run Code Online (Sandbox Code Playgroud)
我不知道在圆圈课上我要做什么,我怎么知道圆点是否在圆圈内?感谢大家.
好的,所以我通过以下代码在地图上绘制了瓷砖:
for (int x = 0; x < WindowsWidth + TextureWidth; x += TextureWidth)
{
for (int y = 400; y < WindowsHeight; y += TextureHeight)
{
spriteBatch.Draw(Texture, new Rectangle((int)x, (int)y, TextureWidth, TextureHeight), Color.White);
}
}
Run Code Online (Sandbox Code Playgroud)
我希望这段代码很好,如果没有,我想听听你的评论.
好吧,所以我不知道如何用这些瓷砖和我的播放器进行矩形碰撞检测.
如果你需要另外的解释,请评论,谢谢.
好吧,所以我想问一下,实际上是否可以从c#到c ++创建一个解析器.
因此,用C#编写的代码能够像用C++编写的代码一样快地运行.
它真的可以吗?我不是在问它会有多难.