一个类型数组同时实现System.Collections.IList和System.Collections.Generic.ICollection<T>接口,都有自己的IsReadOnly特性.但到底是怎么回事?
var array = new int[10];
Console.WriteLine(array.IsReadOnly); // prints "False"
var list = (System.Collections.IList)array;
Console.WriteLine(list.IsReadOnly); // prints "False"
var collection = (System.Collections.Generic.ICollection<int>)array;
Console.WriteLine(collection.IsReadOnly); // prints "True"
Run Code Online (Sandbox Code Playgroud)
该IList阵列的视图表现为我预计,返回相同的阵列本身,但是ICollection<T>该阵列的视图返回true.
这种行为有没有合理的解释,还是编译器/ CLR错误?(如果是后者,我会感到非常惊讶,因为你会想象之前会发现这种情况,但这是违反直觉的,我无法想到解释可能是什么......).
我正在使用C#3.0/.NET 3.5 SP1.
我有一个包含3个控件的表单:
我想要的是让用户在第一个文本框中输入命令,按下按钮以通过第二个文本框输入和接收反馈.
我知道如何使用ProcessStartInfo.RedirectStandardOutput,但是,当我使用时,应用程序挂起StandardOutput.ReadToEnd().
我看了一下异步Process.BeginOutputReadLine()但是,即使我的应用程序没有挂起,不知何故我在文本框中没有得到任何响应,它什么也没做.
这是我的代码:
public partial class MainForm : Form
{
private void MainForm_Load(object sender, EventArgs e)
{
InitializeInterpreter();
}
private void InitializeInterpreter()
{
InterProc.StartInfo.UseShellExecute = false;
InterProc.StartInfo.FileName = "app.exe";
InterProc.StartInfo.RedirectStandardInput = true;
InterProc.StartInfo.RedirectStandardOutput = true;
InterProc.StartInfo.RedirectStandardError = true;
InterProc.StartInfo.CreateNoWindow = true;
InterProc.OutputDataReceived += new DataReceivedEventHandler(InterProcOutputHandler);
InterProc.Start();
}
private static void InterProcOutputHandler(object sendingProcess, DataReceivedEventArgs outLine)
{
if (!String.IsNullOrEmpty(outLine.Data))
{
OutputTextBox.Append(Environment.NewLine + outLine.Data);
}
}
private void Enterbutton_Click(object sender, EventArgs e) …Run Code Online (Sandbox Code Playgroud) 我正在尝试开发一个具有"root"内容的grails应用程序(例如www.mydomain.com/about),但也将支持基于请求的子域的"项目"; 例如myproject.mydomain.com> www.mydomain.com/myproject.作为第一遍,我有以下URL配置:
"/$controller/$action?/$id?" {
...
}
"/$project/$controller/$action?/$id?" {
constraints {
}
}
Run Code Online (Sandbox Code Playgroud)
到目前为止,主要的缺点是$ project变量必须手动注入每个链接(繁琐而不是DRY):
<g:link controller="foo" action="bar" params="${[project: params.project]}">link</g:link>
Run Code Online (Sandbox Code Playgroud)
有没有办法自动将$ project参数注入所有链接(如果存在),还是有更好的方法来解决这个问题?
这是我目前情况的图片: 替代文字http://grab.by/FUM 但我不希望图像在彼此之下,我希望它们在一条线上,一条直线水平线.这是我目前的代码:
<span title="Milestones" class="tl-icon">
<span class="tl-msg">
<span class="tl-msg-inside">
<div class="slice1"></div>
<div class="slice2"></div>
<div class="slice3"></div>
<div class="slice4"></div>
<div class="slice5"></div>
<div class="slice6"></div>
<div class="slice7"></div>
<div class="slice8"></div>
<div class="slice9"></div>
<div class="slice10"></div>
<div class="slice11"></div>
</span>
Run Code Online (Sandbox Code Playgroud)
那么如何让所有图像都成直线呢?
我正在使用win32 API在C中编写应用程序.当我尝试使用HeapRealloc()函数扩大数组的大小时,它会更改数组中的当前值,而不是复制它们.我用来重新分配内存的代码:
BOOL ChangeFeedArraySize(UINT newSize)
{
char tempChar[20] = "";
PFEED tempArr;
if (newSize == 1)
{
tempArr = (PFEED)HeapAlloc(heap, HEAP_ZERO_MEMORY, sizeof(FEED));
}
else
{
tempArr = (PFEED)HeapReAlloc(heap, HEAP_ZERO_MEMORY, categoryArray, newSize * sizeof(FEED));
// FEED - a struct
// PFEED - a pointer to the struct
// categoryArray - array to be reallocated
}
if (tempArr != NULL)
{
MessageBox(NULL, ltoa(HeapSize(heap, 0, tempArr),tempChar,10) , "Heap size after reallocation", MB_OK | MB_ICONEXCLAMATION);
feedArray = tempArr;
return TRUE;
}
else
{
return …Run Code Online (Sandbox Code Playgroud) 如何从Django设置P3P紧凑隐私策略,以便IE在安全设置为HIGH时接受来自我网站的cookie - 即除非有紧凑隐私政策,否则不接受cookie.
干杯盖伊
我见过其他人的问题,但没有发现适用于我在这里尝试实现的目标。
我正在尝试使用 std::sort 和一个通过我的 EntityManager 类对实体进行排序 std::vector<Entity *>
/*Entity.h*/
class Entity
{
public:
float x,y;
};
struct compareByX{
bool operator()(const GameEntity &a, const GameEntity &b)
{
return (a.x < b.x);
}
};
/*Class EntityManager that uses Entitiy*/
typedef std::vector<Entity *> ENTITY_VECTOR; //Entity reference vector
class EntityManager: public Entity
{
private:
ENTITY_VECTOR managedEntities;
public:
void sortEntitiesX();
};
void EntityManager::sortEntitiesX()
{
/*perform sorting of the entitiesList by their X value*/
compareByX comparer;
std::sort(entityList.begin(), entityList.end(), comparer);
}
Run Code Online (Sandbox Code Playgroud)
我收到了十几个错误,比如
: error: no match for …Run Code Online (Sandbox Code Playgroud) 我有以下代码正常工作.但是在我添加一个else语句后,任何事情总是会计算到else
wgetstr(inputWin, ch); //get line and store in ch variable
str = ch; //make input from char* to string
if(str=="m" || str=="M"){
showFeedback("Data Memory Updated");
}
if(str=="p" || str=="P"){
showFeedback("Program Memory Updated");
}
if(str=="g" || str=="G"){
showFeedback("Accumulator, Program Counter, Zero Result Updated");
}
if(str=="e" || str=="E"){
showFeedback("Editing Mode Enabled");
}
if(str=="c" || str=="C"){
showFeedback("Program Copied Into Program Memory");
}
if(str=="r" || str=="R"){
showFeedback("Executing Program");
}
if(str=="x" || str=="X"){
showFeedback("Program Exited");
}
Run Code Online (Sandbox Code Playgroud)
之前的所有内容都根据输入的正确评估.即如果我输入"m",它就会调用showeFeedback("Data Memory Updated"),但是如果我添加以下else语句,无论我输入什么,我总是得到"Invalid Command Entered".
else{
showFeedback("Invalid Command Entered"); …Run Code Online (Sandbox Code Playgroud) 我想要一个有效的算法(或库),我可以在Java中使用它来搜索字符串中的子串.
我想做的是:
给定一个输入字符串 - INSTR:
"BCDEFGH"
还有一组候选字符串--CAND:
"AB","CDE","FG","H","IJ"
在INSTR中查找匹配为子字符串的任何CAND字符串
在这个例子中,我将匹配"CDE","FG"和"H"(但不是"AB"和"IJ")
可能有数千个候选字符串(在CAND中),但更重要的是,我将进行数百万次搜索,因此我需要它快速.
我想使用char数组.此外,我并不喜欢建筑解决方案,例如分发搜索 - 只是在本地进行搜索的最有效的功能/算法.
另外,CAND和INSTR中的所有字符串都将相对较小(<50个字符) - 即目标字符串INSTR相对于候选字符串不长.
我应该提到的更新,在所有INSTR值中,CAND字符串集是不变的.
更新我只需要知道有匹配 - 我不需要知道匹配是什么.
最终更新 由于实施简单,我选择尝试AhoCorsick和Rabin-Karp.因为我有可变长度模式,所以我使用了一个修改过的Rabin-Karp,它会散列每个模式的前n个字符,其中n是最小模式的长度,N则是我的滚动子字符串搜索窗口的长度.对于Aho Corsick,我用过这个
在我的测试中,我在两篇文档新闻论文中搜索了1000个模式,平均1000次迭代等...标准化时间完成:
AhoCorsick:1
拉宾卡尔普:1.8
天真搜索(检查每个模式并使用string.contains):50
*描述以下答案中提到的算法的一些资源:
http://www.seas.gwu.edu/~simhaweb/cs151/lectures/module5/module5.html
http://www.cs.princeton.edu/courses/archive/spr09/cos226/lectures/18SubstringSearch-2x2.pdf