我似乎忘记了一些最基本的继承规则,因为我无法弄清楚为什么这不起作用.我有一个扩展Node的类SuffixNode.
节点:
class Node
{
public char label;
public Node parent;
public Dictionary<char,Node> children;
public Node(Node NewParent, char NewLabel)
{
this.parent = NewParent;
this.label = NewLabel;
children=new Dictionary<char,Node>();
}
}
Run Code Online (Sandbox Code Playgroud)
SuffixNode:
class SuffixNode: Node
{
public Dictionary<String, int> Location=new Dictionary<String, int>();
public SuffixNode(Node NewParent):base(NewParent, '$')
{
}
public void AddLocation(String loc,int offset)
{
this.Location.Add(loc, offset);
}
}
Run Code Online (Sandbox Code Playgroud)
我试图从SuffixNode类调用主程序中的AddLocation方法,但是它给出了一个错误,说明没有这样的方法(在Node类中):
Node n;
char FirstChar = suffix[0]; //first character of the suffix
if (suffix == "")
{
return true;
}
//If the first …Run Code Online (Sandbox Code Playgroud) 我从codeplex下载了DotNetZip,我完全不知道接下来要做什么.
我想提取.zip档案
我知道我用的是这样的东西
string zipToUnpack = "C1P3SML.zip";
string unpackDirectory = "Extracted Files";
using (ZipFile zip1 = ZipFile.Read(zipToUnpack))
{
// here, we extract every entry, but we could extract conditionally
// based on entry name, size, date, checkbox status, etc.
foreach (ZipEntry e in zip1)
{
e.Extract(unpackDirectory, ExtractExistingFileAction.OverwriteSilently);
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,我添加了什么项目和/或我添加了哪些参考?
谢谢
我的印象是我可以创建一个LINQ查询,然后在更改所涉及的参数时重复使用它.但似乎你无法改变源集合.有人可以给我一个很好的解释,为什么,因为我明显误解了一些基本的东西.
这是一些示例代码.
var source = Enumerable.Range(1, 10);
var value = source.Where(x => x > 5);
var first = value.ToArray();
source = Enumerable.Range(11, 20);
var second = value.ToArray();
Run Code Online (Sandbox Code Playgroud)
我期待第一个是6,7,8,9,10,第二个是11到20.
我在C#,.NET 4.0中使用Guid.NewGuid().而且我发现了一个有趣的事实:我生成的每个Guid在13位都有'4'.
da1471ac-11f7- 4 fb7-a7fa-927fffe8a97c
c90058aa-5d7f- 4 bb5-b3a9-c1db197cf3b1
fa68ec75-8cd2- 4 c24-92f8-41dbbdd428a0
d4efd455-e892- 4 3ef-b7bf-9462c5dc4de4
e0a001a0-8969- 4 092-b7a2-e410ed2b351a
30ae98b9-48ae- 4 25d-b6e7-e091502d6ce2
6a95de82-67ff- 4 4c9-9f7b-e37a80462cf7
66768e46-6d60- 4 2b4-b473-2f6f8bc1559a
Run Code Online (Sandbox Code Playgroud)
我在几台机器上试过它并得到了相同的结果.任何人都可以尝试或解释它吗?
简单的检查代码:
static void Main(string[] args)
{
bool ok = false;
for (int i = 0; i < 10000; i++)
{
var guid = Guid.NewGuid();
if (guid.ToString()[14] != '4')
ok = true;
Console.WriteLine(guid);
}
Console.WriteLine(ok ? "No bug!" : "4bug founded!");
}
Run Code Online (Sandbox Code Playgroud) 我在尝试确定地址是 IP 地址还是主机名时遇到问题。我发现的所有内容都表明要使用正则表达式。我不知道如何形成 IF 语句。这是我的代码:
private void btnPingAddress_Click(object sender, EventArgs e)
{
intByteSize = Convert.ToInt32(numericDataSize.Value);
intNumberOfPings = Convert.ToInt32(numericPing.Value);
strDnsAddress = cmbPingAddress.Text;
//If address is IP address:
if (strDnsAddress Contains ((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?")
{
txtPingResults.Text = "Pinging " + strIpAddress + " with " + intByteSize + " bytes of data:" + "\r\n";
}
// If address is hostname:
else
{
strIpAddress = Convert.ToString(Dns.GetHostEntry(strDnsAddress));
txtPingResults.Text = "Pinging " + strDnsAddress + " [" + strIpAddress + "] with " + intByteSize + " …Run Code Online (Sandbox Code Playgroud) 在我的程序中,我有一个dataTable,我想知道是否有一个名称以abc开头的列.例如,我有一个DataTable,它的名字是abcdef.我喜欢使用以下内容找到此列:
DataTable.Columns.Constains(ColumnName.StartWith(abc))
Run Code Online (Sandbox Code Playgroud)
因为我只知道列名的一部分,所以我不能使用Contains方法.有什么简单的方法可以做到这一点吗?
非常感谢.
我有以下代码.如果它不在ValidClaimControl数字中,我将根据以下条件删除RecoveryRecords变量中的数据.
在RecoveryRecords.Remove(s)执行该行之后,它也会从记录变量中删除.我实际上需要来自记录变量的数据.
我想知道如何在记录变量中保留数据?
List<List<Field>> records = new List<List<Field>>();
List<List<Field>> RecoveryRecords = new List<List<Field>>();
//Some Logic here to populate records variable
RecoveryRecords = records;
List<string> validClaimControlNo = new List<string>();
//Some Logic here to populate validClaimControlNo variable
foreach (List<Field> s in RecoveryRecords.ToList())
{
foreach (Field f in s)
{
if (!(validClaimControlNo.Contains(f.Value)))
RecoveryRecords.Remove(s);
}
}
Run Code Online (Sandbox Code Playgroud) 我将我的protobuf消息保存到文件,格式全部搞砸了.我已经看到它在protobug消息以与.proto文件几乎相同的格式保存到磁盘之前完成.我这样做:
using (Stream output = File.OpenWrite(@"logs\listings.txt"))
{
listingBook.AddClisting(_listing);
listingBook.Build().WriteTo(output);
}
Run Code Online (Sandbox Code Playgroud)
但我得到的是一个错误的文件,似乎ENTER与奇怪的标签分开.将它保存到磁盘时我想要的样子就像示例:
# Textual representation of a protocol buffer.
# This is *not* the binary format used on the wire.
person {
name: "John Doe"
email: "jdoe@example.com"
}
Run Code Online (Sandbox Code Playgroud) 我明确地将我的变量转换为in然后使用加号运算符但仍返回44我想知道为什么会发生这种情况我将变量显式转换为int.
byte b = 100;
b = (byte)(b +200);
Run Code Online (Sandbox Code Playgroud)
为什么用这个我的结果是255?
byte b = 100;
b = (byte)(b + 155);
Run Code Online (Sandbox Code Playgroud) 我有一个obect列表,每个对象有一个TimeSpan属性reprsenting时间.我需要得到一个时间最接近输入值的对象.
应该看起来像这样..
List<MyClass> list = new List<MyClass>
{
new MyClass() {Name="midnight", time= new TimeSpan(0,0,0)},
new MyClass() {Name="noon", time= new TimeSpan(12,0,0)},
};
var testOne = GetClosest(new TimeSpan(2, 0, 0),list); // returns midnight
var testTwo = GetClosest(new TimeSpan(8, 0, 0),list); // returns noon
var testThree = GetClosest(new TimeSpan(13, 0, 0),list); // returns noon
var testFour = GetClosest(new TimeSpan(22, 0, 0),list); // returns midnight (that's the tricky one)
Run Code Online (Sandbox Code Playgroud)
这有什么优雅的方式吗?
编辑:当然,列表应该通过,抱歉.
c# ×10
.net ×2
linq ×2
7zip ×1
asp.net-mvc ×1
columnname ×1
dataset ×1
datatable ×1
guid ×1
regex ×1