小编Dmi*_*nko的帖子

选择特定年份Oracle的记录

我有一个存储事务和日期列的oracle表.如果我需要选择一年的记录说2013年我喜欢这样:

select * 
  from sales_table
 where tran_date >= '01-JAN-2013'
   and tran_date <= '31-DEC-2013'
Run Code Online (Sandbox Code Playgroud)

但我需要一种直接的方式来选择一年的记录,比如从应用程序传递参数'2013',以便在一年内从记录中获得结果而不给出范围.这可能吗?

sql oracle11g

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

CultureInfo瑞典语

我想将日期时间转换为瑞典文化.

DateTime.Today.ToString("dd MMMM yyyy");
Run Code Online (Sandbox Code Playgroud)

上面的代码行为给出了2013年12月27日的结果

我想要用瑞典语显示十二月的结果.

c# asp.net culture

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

如何在不将最后一行留空的情况下向richtextbox添加新行?

我正在为我正在创建的程序创建一个日志系统,我现在已将它用于执行此操作的位置:

void outToLog(string output)
{
    logRichTextBox.AppendText(output + "\r\n");
    logRichTextBox.ScrollToCaret();
}
Run Code Online (Sandbox Code Playgroud)

但它最终输出了RichTextBox空白的最后一行(因为我正在使用\n),我希望最后一行只是输出,而不是空行.另一种选择是让我把它"\r\n"放在开头,但是除了它在开头之外,它只有相同的影响RichTextBox.

救命?谢谢

c# winforms

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

array.Take(13).Skip(x)正在减去take

这是针对Project Euler,问题8.

我试图foreach通过数组,每次跳过最后一个数字并拉出数组中的下13个相邻数字.

我的代码:

for(int x = 0; x < 987; x++)
{
    foreach(int number in numbers.Take(13).Skip(x))
    {
        hold = hold * number;
        adjacent[index] = number;
        index++;
    }

    if (hold > product)
    {
        product = hold;
    }

    Array.Clear(adjacent, 0, adjacent.Length);
    index = 0;
    hold = 1;
}
Run Code Online (Sandbox Code Playgroud)

我遇到的问题是,每次通过数组枚举时,它会减去x的数量,从它通过列表的次数减去13,即13.

所以当x为5时,它只会通过数组8次.

如何在一次遍历13个数字的位置修复它?

c# linq foreach

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

Linq OrderBy用于对具有相同集合的对象进行分组

我有一组自己包含一组的对象.

private class Pilot
{
    public string Name;
    public HashSet<string> Skills;
}
Run Code Online (Sandbox Code Playgroud)

这是一些测试数据:

public void TestSetComparison()
{
    var pilots = new[] 
    {
        new Pilot { Name = "Smith", Skills = new HashSet<string>(new[] { "B-52", "F-14" }) },
        new Pilot { Name = "Higgins", Skills = new HashSet<string>(new[] { "Concorde", "F-14" }) },
        new Pilot { Name = "Jones", Skills = new HashSet<string>(new[] { "F-14", "B-52" }) },
        new Pilot { Name = "Wilson", Skills = new HashSet<string>(new[] { "F-14", "Concorde" …
Run Code Online (Sandbox Code Playgroud)

c# linq

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

List or Dictionary of Objects inside Class

A friend and I (both new in programming) were arguing if it was wise to include a Dictionary inside a Class that contains all instances of that class.

I say that is better that the dictionary is in the main instead in the class itself.

我没有充分的理由说出为什么,但是我从未见过有类记录已创建对象的记录。

您能给我每种方法的利弊吗?

提前致谢。

A:

    class Table
    {
      public static Dictionary<int,Table> Tables = new Dictionary<int, Table>();
     ...
     public table (int ID)  // constructor
     {
      ...
      Tables.Add(ID,this);
     }   
    }
Run Code Online (Sandbox Code Playgroud)

B:

     class Program
     {
      public Dictionary<int,Table> Tables = …
Run Code Online (Sandbox Code Playgroud)

c# dictionary list

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

将字符串拆分为单词,然后重新加入其他数据

我有一种方法可以用来Regex在文本中查找模式string。它可以工作,但是并不合适,因为它要求文本以确切的顺序出现,而不是将短语视为一组单词。

    public static string HighlightExceptV1(this string text, string wordsToExclude)
    {
        // Original version
        // wordsToExclude usually consists of a 1, 2 or 3 word term.
        // The text must be in a specific order to work.

        var pattern = $@"(\s*\b{wordsToExclude}\b\s*)";

        // Do something to string...
    }
Run Code Online (Sandbox Code Playgroud)

此版本对以前的版本进行了改进,因为它确实允许单词以任何顺序进行匹配,但是由于删除了间距并用管道替换了间距,因此最终输出中会出现间距问题

    public static string HighlightExceptV2(this string text, string wordsToExclude)
    {
        // This version allows the words to be matched in any order, but it has
        // …
Run Code Online (Sandbox Code Playgroud)

c# regex asp.net string

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

为什么Select会将我的while循环变成无限循环?

在工作中,我遇到了一个奇怪的问题,本来希望终止的循环实际上无限期地运行

我将问题追溯到使用Select。有趣的是,当我在后面添加一个权利时,循环按预期终止。我将其简化为一个小例子。.ToList()Select

class WrappedBool
{
    public WrappedBool(bool inner)
    {
        InnerBool = inner;
    }
    public bool InnerBool { get; set; } = false;
}

// remove .ToList() here and the following loop will go infinite
IEnumerable<WrappedBool> enumerable = 
   new List<bool>() { false, true, false }
  .Select(b => new WrappedBool(b))
  .ToList();

while (enumerable.Any(wb => !wb.InnerBool))
{
    WrappedBool firstFalse = enumerable.Where(wb => !wb.InnerBool).First();
    firstFalse.InnerBool = true;
}
Run Code Online (Sandbox Code Playgroud)

尽管我不必处理代码不再终止的问题,但我仍然想知道这种行为最初来自何处。

c# linq

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

用类常量值填充 List&lt;string&gt; 的方法。C#

我需要创建一种方法来填充 List<string>使用在自己的类中定义的常量的值。

为您提供类中定义的众多(20总共)const蚂蚁的快速示例:

private const string NAME1 = "NAME1";
private const string NAME2 = "NAME2";
private const string NAME3 = "NAME3";
...
Run Code Online (Sandbox Code Playgroud)

如您所见,常量的名称等于它的值,如果这有帮助的话。

到目前为止,查看我在 StackOverflow 中找到的关于类似问题的不同类型解决方案的示例,我想出了这个:

public static List<string> GetConstantNames()
{
   List<string> names = new List<string>();
   Type type = typeof(ClassName);

   foreach (PropertyInfo property in type.GetType().GetProperties())
   {
      names.Add(property.Name);
   }

   return names;
}
Run Code Online (Sandbox Code Playgroud)

我作为程序员的经验相当低,就像我使用 C# 的经验一样;我不确定是否type.GetType().GetProperties()引用了常量名称,该property.Name行也会发生同样的情况。

这种方法是否符合我的要求?

c# reflection constants

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

比较两个字典(Key,value)并返回不具有相同值的Key

我对 C# 有点陌生,想要在比较两个字典时识别不具有相同值的键。

我的字典是dict => KeyValuePair<string, string>。我有两本字典,比如 -

dict1 => {"a":"False","b":"amazonaws.com","c":"True"}
dict2 => {"a":"True","b":"amazonaws.com","c":"False"}
Run Code Online (Sandbox Code Playgroud)

我想比较两个字典并返回一个具有键 ["a", "c"] 的变量,如上面的示例所示,这些键具有不同的值。

目前我编写的逻辑只会区分其他字典中不存在的键。

Dictionary dictExcept = null;
foreach (IDictionary kvp in dict1.Cast<object>().Where(kvp => !dict2.Contains(kvp)))
    {
        dictExcept.Add(kvp.Keys, kvp.Values);
    }
return dictExcept ;
Run Code Online (Sandbox Code Playgroud)

.net c# dictionary

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

标签 统计

c# ×9

linq ×3

asp.net ×2

dictionary ×2

.net ×1

constants ×1

culture ×1

foreach ×1

list ×1

oracle11g ×1

reflection ×1

regex ×1

sql ×1

string ×1

winforms ×1