小编Moo*_*eef的帖子

C#语法问题

我在c#示例中看到了以下代码:

public void AddScreen(GameScreen screen, PlayerIndex? controllingPlayer)
{
    screen.ControllingPlayer = controllingPlayer;
    screen.ScreenManager = this;
    screen.IsExiting = false;
}
Run Code Online (Sandbox Code Playgroud)

而且我不知道?在PlayerIndex之后它正在做什么,它是一个枚举,并且在课堂上它的每一个通知都在?背后.我的问题:它做了什么,它叫什么,你为什么要用它.

我用谷歌搜索了这个,但它没有让我走远,因为我不知道这个编码的名称和谷歌过滤掉搜索查询中的问号

c# syntax enums nullable

3
推荐指数
1
解决办法
208
查看次数

C ++我的一流操作员重载,带有标头

我是C ++的新手,尽管我确实知道一般的C语法。我一直在尝试创建一个带有运算符重载的类。但是我无法使它工作。好吧,让它起作用。

同一源中的工作运算符重载:

//test.cpp
#include <iostream>

class Fraction
{
    int gcd(int a, int b) {return b==0 ? a : gcd(b,a%b); }
    int n, d;
public:
    Fraction(int n, int d = 1) : n(n/gcd(n,d)), d(d/gcd(n,d)) {}
    int num() const { return n; }
    int den() const { return d; }
    Fraction& operator*=(const Fraction& rhs) {
        int new_n = n*rhs.n / gcd(n*rhs.n, d*rhs.d);
        d = d*rhs.d / gcd(n*rhs.n, d*rhs.d);
        n = new_n;
        return *this;
    }
};
std::ostream& operator<<(std::ostream& out, const Fraction& f){ …
Run Code Online (Sandbox Code Playgroud)

c++ class operator-overloading

2
推荐指数
1
解决办法
2万
查看次数

扩展一个类使其成为可转换的

我想扩展一个类(Vector2),使其可以转换为Point.我怎么做?

部分问题:

  1. 扩展课程
  2. 将类转换为另一个类

最后我希望能够做到这一点:

Vector2 foo = new Vector2(5.2f);  // X = 5.2f Y = 5.2F
Point red = new Point(2,2);  // X = 2 Y = 2
red = foo;  // I know that you can make classes convert themselves automatically... somehow?
// Now red.X = 5 red.Y = 5
Run Code Online (Sandbox Code Playgroud)

c# xna

1
推荐指数
1
解决办法
808
查看次数

一个类中的C#命名空间

我有类和方法的基本知识.我可以创建类,并为它们定义方法:

myClass.awesome("test"); (example)
Run Code Online (Sandbox Code Playgroud)

但我看到一个类有以下方法:

anotherClass.something.methodName(arguments);
Run Code Online (Sandbox Code Playgroud)

如何创建具有其他命名空间的方法.我试过了:

public Class test
{
    namespace subname
    {
        public void Test()
        {
            return;
        }
    }

    //also i tried:
    public void lol.Test()
    {
        return;
    }
}
Run Code Online (Sandbox Code Playgroud)

但他们都说这不是那样做的,它是如何正确的,所以我可以更好地订购/分组我的方法?

请不要问为什么,或者提供替代方案,我只想创建一个具有这种方法的类(Class.sub.Method()Class.sub.sub....sub.Method())

感谢您阅读我的问题,并可能给出答案:)

c# methods inheritance nested class

0
推荐指数
1
解决办法
229
查看次数

标签 统计

c# ×3

class ×2

c++ ×1

enums ×1

inheritance ×1

methods ×1

nested ×1

nullable ×1

operator-overloading ×1

syntax ×1

xna ×1