小编Mon*_*Zhu的帖子

如何在 NLog.Config 中使用来自不同类的变量?

我有一个static包含路径的字段的类。

public static class PfadSammlung
{
    public static string Path_Example = @"C:\temp";
}
Run Code Online (Sandbox Code Playgroud)

如何在NLog.Config文件中使用此路径来指定目标的文件名?

public static class PfadSammlung
{
    public static string Path_Example = @"C:\temp";
}
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激。

c# config nlog path

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

选项卡按钮切换到Windows窗体应用程序中的错误控件

我正在使用c#在Windows窗体应用程序中工作.我有两个字段,形式为"用户名"和"密码",两个按钮"登录"和"取消".在表单加载光标放在用户名文本框中,这是好的.

但是当我TAB从键盘上按下而不是转到密码文本框时,它会转到"登录"按钮.我怎么设置这个?

此外,选择所有文本的快捷方式 CTRL+ A在文本字段中不起作用.有帮助吗?

c# visual-studio winforms

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

Linq添加动态where子句

我试图在我的linq代码中添加一个动态where子句.但是我收到以下错误.其他样本提供相同的代码但它们工作正常,所以我不确定我是否错过了什么.

var toBeReturn = db.estimate.ToList();
if(sname != null)
{
    toBeReturn =  toBeReturn.Where(x => x.estimate_status == sname);
}
Run Code Online (Sandbox Code Playgroud)

错误:

严重级代码说明项目文件行抑制状态错误CS0266无法将类型"System.Collections.Generic.IEnumerable"隐式转换为"System.Collections.Generic.List".存在显式转换(您是否错过了演员?)

请帮忙

c# linq

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

在字符串数组中找到最短的字符串

我需要提供一个解决方案来查找字符串数组中的最短字符串.我当时认为应该比较每个字符串的长度才能返回.

这是我被困的地方

static void Main(string[] args)
{
    //find the shortest string in an array of string
    string[] names = new string[3]{
        "Tom", "and", "jerry"
    };

    foreach(string name in names){
        Console.Write(name + ", ");
    }

    Console.ReadKey();
}
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮我比较部分并解释它

.net c# arrays string

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

C# GDI 如何绘制文本以适合矩形?

我们可以轻松地在矩形内绘制文本。

在此处输入图片说明

目前我想在里面绘制一个文本并拟合一个矩形。

在此处输入图片说明

请帮忙。

c# gdi drawtext

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

圆形.99表示十进制值

我想将价格(加倍)四舍五入到最接近的xx.99

例如:

10.3 ==> 10.99
10 ==> 10.99
10.97 ==> 10.99
10.50 ==> 10.99
10.99 ==> 10.99
10.01 ==> 10.99

我做了Math.Round,Math.Truncate,Math.Ceiling但它不能正常工作的情况下所有.我可以转换string,拆分和替换,但我认为这不是一个好方法.

我能怎么做?

c# decimal rounding

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

使属性getter和setter等于某事(auto-property initializer)

有什么区别:

public List<MyType> Something{ get; set; } = new List<MyType>();
Run Code Online (Sandbox Code Playgroud)

public List<MyType> Something{ 
    get{
        return new List<MyType>();
    }
    //set...
}
Run Code Online (Sandbox Code Playgroud)

上下文:
我不确定我在代码中看到的行为.构造函数null上有一个服务,但在未来的方法调用中,我假设的是类的相同实例.

c# properties

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

循环时,加上第五,第十,第十五......等数

需要做什么的示例:

需要做什么的例子

"输入了几个数字(输入再次以0结尾).确定并打印第5个,第10个,第15个数字的总和等."

有人可以告诉我我的代码有什么问题吗?

class Program
{
    static void Main(string[] args)
    {
        int counter = 0;
        int sum = 0;

        Console.Write("Enter a number: ");
        int number = int.Parse(Console.ReadLine());

        while (number != 0)
        {
            if (number > 0 && counter % 5 == 0)
            {
                counter++;
                sum = sum + number;
            }
            Console.Write("Enter a number: ");
            number = int.Parse(Console.ReadLine());
        }

        Console.WriteLine("Sum of the 5th, 10th, 15th ... number is = {0}", sum);
        Console.ReadKey();
    }
}
Run Code Online (Sandbox Code Playgroud)

c# iteration while-loop

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

按嵌套集合的 LINQ 过滤器列表

我有以下类层次结构:

public class SportPlan
{
    public Guid Id { get; set; }
    public string Name { get; set; }
    public List<Record> RecordFields { get; set; }
}

public class Record
{
    public Guid Key { get; set; }
    public string Alias { get; set; }
    public List<Value> Values { get; set; }
}

public class Value
{
    public int Index { get; set; }
    public List<DayOfWeek> DaysOfWeek { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我需要SportPlan.RecordFieldsdayOfWeek(.NET enum)过滤并Value使用 …

c# linq

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

移除动态控制

我有一个带有动态添加控件的表单。当用户单击 next 时,必须删除所有动态控件。我的代码只删除了其中的一些。

例如dtxt2,第一次不会被删除,但如果我第二次运行删除功能,它会被删除。

这是添加动态的函数:


void TextboxesStep21()
{
    removeDynamics();
     TextBox dtxt1 = new TextBox();
     dtxt1.Name = "DynamicTextBox1";
     dtxt1.Location = new System.Drawing.Point(336, 125);
     dtxt1.Text = ((diameterOfDrivingWeel + spindleSlope)*10).ToString();
     this.Controls.Add(dtxt1);
     
    TextBox dtxt2 = new TextBox();
    dtxt2.Name = "DynamicTextBox2";
    dtxt2.Location = new System.Drawing.Point(336, 148);
    dtxt2.Text = gearingRatioDen.ToString();
    this.Controls.Add(dtxt2);

    TextBox dtxt3 = new TextBox();
    dtxt3.Name = "DynamicTextBox3";
    dtxt3.Text = gearingRatioNum.ToString(); ;
    dtxt3.Location = new System.Drawing.Point(336, 171);
    this.Controls.Add(dtxt3);


    pictureBox1.SendToBack();
    pictureBox2.SendToBack();
}

Run Code Online (Sandbox Code Playgroud)

这是我的删除功能

void removeDynamics()
{
    foreach (Control x in this.Controls)
    {
        if (x.Name.Contains("Dynamic")) …
Run Code Online (Sandbox Code Playgroud)

c# windows-forms-designer winforms

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