Tag:

C#:为派生类inheritance单独的静态成员

我的问题简要说明: class A { /* Other stuff in my class*/ protected static staticMember; } class B : A { /* Other stuff in my class*/ // Will have A.staticMember but I want B.staticMember (same type) } class C : A { /* Other stuff in my class*/ // Will have A.staticMember but I want C.staticMember […]

课程是否仍应作为推荐密封?

我知道这在“技术上”是这个问题的重复。 我应该推荐默认的密封类吗? 但是我再问一遍,因为显然这个建议已经改变了1次,虽然我在过去几年里找不到任何关于它的事情,或者现在越来越多的人推荐AGAINST密封课程,这要归功于改进在测试中(这是主要原因之一),处理器速度(速度差现在可以忽略不计)等。 我正在试图找出最新的天气指南是什么,以便将classes标记为sealed 。 1 Essential C#6.0(第5版) ,Mark Michaelis(合着者Eric Lippert): “一般来说,将一个类别标记为密封很少进行,并且应该只保留那些有充分理由支持这种限制的情况。实际上,离开类型未开封的情况越来越令人满意,因为unit testing因此而变得突出需要支持mock(测试双重)对象创建来代替实际的实现。“ 这是硬拷贝certificate,因为其他人都是口口相传。

MustInherit和抽象类之间的区别

有人可以向我解释抽象类和标记为MustInherit的类之间的区别吗? 两者都可以实现共享和实例构造函数和逻辑。 两者都可以/必须inheritance。 那么为什么要使用一个而不是另一个呢?

将类转换为数组

我有一个DisplayedData类…… public class DisplayedData { private int _key; private String _username; private String _fullName; private string _activated; private string _suspended; public int key { get { return _key; } set { _key = value; } } public string username { get { return _username; } set { _username = value; } } public string fullname […]

将null转换为对象?

我今天遇到了这个代码 AsyncInvoke(OnTimeMessageTimer, (object)null, (ElapsedEventArgs)null); 这有什么不对吗?

将二维数组转换为对象c#

这一切都源于查询Google Analytics数据。 对于基本查询,更改的主要因素是维度和指标 。 返回的对象是一个名为GaData的类型,您需要的实际结果驻留在GaData.Rows中。 GaData.Rows的格式如下所示: 每个维度首先会有一行,在此示例中,“新访问者”有一行,“返回访问者”有第二行。 在这些行中,将包含另一组包含Dimension值的行,然后是您指定的每个度量标准(我只要求一个度量标准)。 到目前为止,我的课程设置如下: public class Results { public List Dimensions { get; set; } } public class Dimension { public string Value { get; set; } public List Metrics { get; set; } } public class Metric { public int Value { get; set; } } 最后,也许它刚刚晚了,我的大脑function不好,但我将这些数据转换为Results类型有点困难,我认为是因为多层。 有帮助吗? 编辑 […]

将两个富文本框滚动在一起,我无法弄明白

我想滚动聊天框时向上滚动时间框。 (不一定反之亦然) 我找到了以下代码: /// Subclass RichTextBox to add the capability to bind scrolling for multiple RichTextBoxs. /// This is useful for ‘parallel’ RTBs that require synchronized scrolling. /// Taken from https://gist.github.com/593809 /// Added WM_HSCROLL /// Added BindScroll() to form a two-way linkage between RichTextBoxes. /// Example usage showing how to bind 3 RichTextBoxes together: /// […]

我试图在一个类中创建一个方法,并尝试通过单击按钮从另一个类(窗体)调用

这是我的第一堂课: namespace WindowsFormsApplication2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); /*_enemy = new Class1(this); int y = Class1.MyMethod(0); textBox1.Text = Convert.ToString (y);*/ } private Class1 _enemy; private void button1_Click(object sender, EventArgs e) { _enemy = new Class1(this); int y = Class1.MyMethod(); textBox1.Text = Convert.ToString(y); } } } 这是我的第二堂课: namespace WindowsFormsApplication2 […]

在对象中创建一类对象

我看起来似乎是一个简单的问题,但由于某种原因,我遇到了一个问题,让我的大脑围绕着一个带有多个对象的对象的概念。 例如,假设我们有一个带有标题和页脚的对象,其间有多个对象。 与报告一样,标题将具有名称和地址。 页脚将总共有购买的项目。 中间将是包含部件号,描述和价格的订单项。 我想我可以有一个带有页眉,页脚和一个行项目对象数组的对象,它们都有自己的属性。 我使用报告作为例子,因为这是我能想到的唯一一个能够接近解释我的问题的概念。 有人可以给我发一个链接或解释如何创建这种类型的对象。 我正在使用VS 2010和VB.net,我可以从C#转换为VB。 Report Object Header Object Property Name Property Date End LineItem() Array Object Property Part Number Property Part Description Property Number of Items Property Per Item Price Property Total price End Footer Object Property Total Items count Property Total Price End End

获取其他类的变量

我正在进行乒乓球游戏,因为我是编程新手,我不知道如何获得另一个类变量。 我有单独的课程,绿色和蓝色的拨片,一个球和game1.cs。 我用bool movingUp控制球的运动,movingLeft; 它从屏幕的边界反弹,但我不知道如何使它与桨一起工作。 基本上,我如何检查球拍的位置,当球接触球拍时,它会反弹? 我的意思是,如何检测碰撞? public class Ball { ParticleEngine particleEngine; GraphicsDeviceManager graphics; Texture2D texture; Vector2 position; Boolean movingUp, movingLeft; Vector2 origin; public Ball() { position = new Vector2(800 / 2, 330); } public void LoadContent(ContentManager Content) { texture = Content.Load(“ball”); movingLeft = true; //Particle Engine List textures = new List(); textures.Add(Content.Load(“pixel”)); particleEngine […]