小编Joa*_*nge的帖子

如何设计在xml中存储复杂对象设置

我试图在对象本身上存储每个对象状态的自定义设置,但我不知道如何以面向对象的方式执行此操作.所以:

xml文件中的一个部分是:

<ObjectType>
Run Code Online (Sandbox Code Playgroud)

可以是Blur, Sharpen, Smooth,等等

但是说,Blur只有在类型为的情况下才能存储其他属性Blur,例如:

<BlurType>Gaussian, Smart, etc</BlurType>
Run Code Online (Sandbox Code Playgroud)

此外,我不确定是否应将这些存储为:

<a>something</a>
Run Code Online (Sandbox Code Playgroud)

要么

<a>Type=something</a>
Run Code Online (Sandbox Code Playgroud)

xml

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

将自动属性传递为ref

C#编译器不允许这样做.这是什么原因?我可以使用哪些解决方法?

基本上我需要交换一些值,但不想全部使用相同的交换代码.

.net c# automatic-properties

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

如何创建字符串或整数的枚举器/生成器?

我希望有一个枚举器/生成器,每当我调用GetNext时,它总会为我提供下一个值?这可能吗?

Examples:

myStringEnumerator.GetNext()
  -> returns "Identifier01.xml"
myStringEnumerator.GetNext()
  -> returns "Identifier02.xml"
myStringEnumerator.GetNext()
  -> returns "Identifier03.xml"
myStringEnumerator.GetNext()
  -> returns "Identifier04.xml"
myStringEnumerator.GetNext()
  -> returns "Identifier05.xml"
...

evenNumberGenerator.GetNext()
  -> returns 0
evenNumberGenerator.GetNext()
  -> returns 2
evenNumberGenerator.GetNext()
  -> returns 4
evenNumberGenerator.GetNext()
  -> returns 6
evenNumberGenerator.GetNext()
  -> returns 8
evenNumberGenerator.GetNext()
  -> returns 10
...
Run Code Online (Sandbox Code Playgroud)

我不会在一个地方进行迭代,而是在许多地方和非常不同的时间进行迭代.

我该如何以最优雅的方式做到这一点?如果它也快,那也很好.

.net c# collections ienumerable

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

在listview上绘画会禁用listview项目上的重绘

这是什么原因?

我重写OnPaintBackground并绘制一个字符串.直到我在构造函数中调用它才会显示:

this.SetStyle ( ControlStyles.UserPaint, true );
Run Code Online (Sandbox Code Playgroud)

但后来我没有在列表视图中看到这些项目.

为什么以及如何解决这个问题?

编辑:代码

    protected override void OnPaintBackground ( PaintEventArgs pevent )
    {
        base.OnPaintBackground ( pevent );

        // Create string to draw.
        String drawString = "76";

        // Create font and brush.
        Font drawFont = new Font ( "Arial", 36 );
        SolidBrush drawBrush = new SolidBrush ( Color.Blue );

        // Create point for upper-left corner of drawing.
        PointF drawPoint = new PointF ( 150.0F, 150.0F );

        // Draw string to screen.
        pevent.Graphics.DrawString ( drawString, drawFont, …
Run Code Online (Sandbox Code Playgroud)

.net c# listview gdi+ winforms

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

如何在运行时以编程方式转换对象?

假设我有一个自定义控件,如:

MyControl : Control
Run Code Online (Sandbox Code Playgroud)

如果我有这样的代码:

List<Control> list = new ...
list.Add (myControl);

RolloutAnimation anim = list[0];
Run Code Online (Sandbox Code Playgroud)

我知道我可以在编译时完成它,但我想在运行时执行它并访问MyControl特定的功能.

.net c# casting winforms

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

如何在C#中实现电影的运行时?

我正在Movie上课,我需要Runtime为每部电影定义2小时15分45秒.这是否有内置类型BCL

如果没有,我应该为此定义什么类型?应该叫它Interval还是什么?

.net c#

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

如何在实时应用程序中防止或最小化.NET GC的负面影响?

是否有任何提示,技巧和技术可以防止或最大限度地减少由于.NET GC导致的应用程序的减速或临时冻结?

也许有些东西:

  1. 尽可能尝试使用结构,除非数据太大或者主要在其他类中使用,等等.

.net c# garbage-collection

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

C#控制流程

我做了一个数字,用C#请求2个数字,然后用相应的消息回复.怎么会对第二个号码不起作用?无论我为第二个号码输入什么,我都会收到消息"你的号码在0-10范围内".

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string myInput;  // declaring the type of the variables
            int myInt;

            string number1;
            int number;


            Console.WriteLine("enter a number");
            myInput = Console.ReadLine(); //muyInput is a string  which is entry input
            myInt = Int32.Parse(myInput); // myInt converts the string into an Integer

            if (myInt > 0)
                Console.WriteLine("Your number {0} is greater than zero.", myInt);
            else if (myInt < 0)
                Console.WriteLine("Your number {0} …
Run Code Online (Sandbox Code Playgroud)

c#

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

是否有内置的Python函数来生成从0到1的100个数字?

我期待这样的事情range,而是一个可以让我指定的开始和结束值,与我多少个号码需要,我想以类似的方式来使用集合沿range中使用for loops.

python math loops range sequence

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

有没有办法在Python中包含文件的内容作为代码(编译时)?

我正在使用第三方应用程序的Python集成,其中Python代码内部存储在二进制文件中.所以我想将代码与它分开.我可以创建一个模块,但我需要包含的代码本身不起作用,因为它包含仅在该上下文中有效的本地化等.

我基本上是在编译时寻找一个复制粘贴解决方案.

在Python中有没有办法做到这一点?

python

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