它们之间的区别是什么:
public class Person
{
public string Name { get; set; }
public Person(string name)
{
this.Name = name;
}
}
public class Person
{
public string Name { get; set; }
public Person(string name)
{
Name = name;
}
}
它们不都做完全一样的事情吗?
谢谢。
VS 2013速递论坛似乎不存在于微软,所以我想在这里问一问。
我正在使用2013创建一个C#项目。我希望能够向项目中添加一个whatever.cs文件,这样我就可以将额外的函数放在那里,而不是在默认的Program.cs文件中。在过去,我们可以使用#include导入C中的代码文件,但是Visual中的C#似乎不这样做。
我已经成功地添加了一个.cs文件,在其中创建了一个类,然后实例化了这个类,并从Program.cs中调用了它的方法,但是我希望不必实例化一个变量,只需调用something.MyFunction()之类的函数就可以执行另一个文件中存在的一些代码。
这有可能吗?如果没有,有人
我在我的应用程序中集成的一些开放源代码包含一些类,这些类包含了类似的代码:
class SomeClass < SomeParentClass
def self.new(options = {})
super().tap { |o|
# do something with `o` according to `options`
}
end
def initialize(options = {})
# initialize some data according to `options`
end
end
据我所知,self.new和i
可能重复:
我在msdn上读到了关于C#命名约定的文章,但是他们没有提到命名私有字段和参数。
public void SetAnimation(int framesX, int framesY)
{
framesX = framesX; // the first one is private class member
framesY = framesY;
}
我必须命名私有字段与参数不同。我不能两个人都做骆驼案子。你有什么建议?
为了在我的MonoDroid应用程序中使用,我正在转换一些java代码C#。我有一些代码片段,其中声明了接口,然后将其初始化为对象。我不是百分之百确定在C#中实现这些的最佳方法。
例如:
public class NumberPicker {
public interface Formatter {
String toString(int value);
}
public static final NumberPicker.Formatter TWO_DIGIT_FORMATTER =
new NumberPicker.For
大约一年前,我开始涉足Lua,并决定学习C#,而不是当我最近发现Unity的时候!
所有这些都非常令人兴奋,但我对Lua的理解是非常有限的,我真的很难理解这个概念:
// C# Random Number:
Random r = new Random();
r.Next(5, 10)
据我所知,在卢阿,我只会这样做:
-- Lua Random Number:
r = math.random(5, 10)
我的问题是:
在C#中,为什么我必须创建这个随机类的实例?为什么我不能从Random.Next(5,10)方法中获取一个随机值并将其赋值给'r‘,其语法类似于上面的Lu
我目前正在将游戏引擎的语言从c++更改为c#。在c++中,我可以简单地在我的类中继承两个类,这使得事情变得简单得多,但是我发现在c#中这是不可能的。相反,我必须使用接口。
我到处寻找示例,我知道这里有很多示例;我不知道如何在我的示例中实现它。
请注意,我遵循了一个教程来生成此代码,因此我关于多态性的知识可能是错误的。
C++代码:
class TileMap : public sf::Drawable, public sf::Transformable
{
...
private:
//this virtual function is simply so we don'
在Andrew Tolson的Pro中,作者说当非泛型类扩展泛型基类时,派生类必须指定C#参数。
// Assume you have created a custom
// generic list class.
public class MyList<T>
{
private List<T> listOfData = new List<T>();
}
// Non-generic classes must specify the type
// parameter when deriving from a
// generic base class.
我正在学习如何使用LiteDB。下面是我用来将.Net对象插入到数据库中的一小段C#代码:
// Create new YacksProjectInfo object and insert it into the database
YacksProjectInfo projectInfo = new YacksProjectInfo(AssemblyName, moduleNumber);
yacksProjects.Insert(projectInfo); // Id field generated automatically
yacksProjec
我正在重写其他人的代码,我遇到了两个类,它们直接相互引用,并相互调用方法。就像这样(在C#中的例子):
class A {
B otherClass;
public A() {
this.otherClass = new B(this);
}
// Other methods here call methods on B
}
class B {
A otherClass;
public B(A otherClass) {
this.otherClass = otherClass;
}
// Other methods here call met
我正在学习一个教程,作者在构造函数中创建类的属性。是否有理由这样做,而不是在类本身中创建属性?
我的背景是C#,所以我在构造函数中传递参数的原因是确保类实例化时传递构造函数中的参数。
以下是作者所写的代码:
export class Exercise {
constructor(
public name: string,
public title: string,
public description: string,
public image: string,
public nameSound?: str