我有一个存储事务和日期列的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',以便在一年内从记录中获得结果而不给出范围.这可能吗?
我想将日期时间转换为瑞典文化.
DateTime.Today.ToString("dd MMMM yyyy");
Run Code Online (Sandbox Code Playgroud)
上面的代码行为给出了2013年12月27日的结果
我想要用瑞典语显示十二月的结果.
我正在为我正在创建的程序创建一个日志系统,我现在已将它用于执行此操作的位置:
void outToLog(string output)
{
logRichTextBox.AppendText(output + "\r\n");
logRichTextBox.ScrollToCaret();
}
Run Code Online (Sandbox Code Playgroud)
但它最终输出了RichTextBox空白的最后一行(因为我正在使用\n),我希望最后一行只是输出,而不是空行.另一种选择是让我把它"\r\n"放在开头,但是除了它在开头之外,它只有相同的影响RichTextBox.
救命?谢谢
这是针对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个数字的位置修复它?
我有一组自己包含一组的对象.
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) 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) 我有一种方法可以用来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) 在工作中,我遇到了一个奇怪的问题,本来希望终止的循环实际上无限期地在运行。
我将问题追溯到使用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)
尽管我不必处理代码不再终止的问题,但我仍然想知道这种行为最初来自何处。
我需要创建一种方法来填充 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# 有点陌生,想要在比较两个字典时识别不具有相同值的键。
我的字典是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)