我有一个项目,从c:\ work\SomeVariantFolder\MySolution\MyProject\Bin\Debug运行,我需要从其中一个子文件夹执行该项目的命令行:c:\ work\SomeVariantDev.我面临的问题是从我的项目运行的文件夹到我想要运行此命令行的文件夹.
请注意,我不能将批处理文件用于此解决方案.
我试图做的 - 声明一个私有方法,它从同一个进程执行三个命令,向上运行四个文件夹,然后执行我的命令,但这似乎不起作用.我觉得我在这里做错了,因为如果我从c:\ work\SomeVariantFolder \运行这个命令,那就好了.
var process = new System.Diagnostics.Process();
var startInfo = new System.Diagnostics.ProcessStartInfo
{
WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal,
FileName = "cmd.exe",
RedirectStandardInput = true,
UseShellExecute = false
};
process.StartInfo = startInfo;
process.Start();
process.StandardInput.WriteLine("cd..");
process.StandardInput.WriteLine("cd..");
process.StandardInput.WriteLine("cd..");
process.StandardInput.WriteLine("cd..");
process.StandardInput.WriteLine("my command");
Run Code Online (Sandbox Code Playgroud)
请注意,由于我的解决方案的性质,我不能使用批处理文件,不能使用c:\ work\SomeVariantFolder作为硬编码文件夹,因为"SomeVariantFolder"名称在某些情况下可能会更改.
任何帮助都会得到满足
我有一个像这样定义的对象字典 -
Dictionary<string, MyObject> myObjectDictionary
Run Code Online (Sandbox Code Playgroud)
我想根据索引和项目数来获取字典中的项目.我正在尝试使用Skip和Take.但这需要重新制作它Dictionary<string, MyObject>.如何才能做到这一点?我应该采取不同的方式吗?
这是我的代码,尝试重铸失败 -
Dictionary<string, MyObject> myObjectDictionary = FillMyObjectDictionary();
var mySmallerObjectDictionary = myObjectDictionary.Skip(startNumber).Take(count);
//THE FOLLOWING DOES NOT WORK
Dictionary<string, MyObject> myNewObjectDictionary = (Dictionary<string, MyObject>)mySmallerObjectDictionary
Run Code Online (Sandbox Code Playgroud) 我试图找到一种方法来循环ASP占位符中"Checkbox"类型的所有控件,然后在循环中对控件执行某些操作.
问题是我无法访问控件...这是我到目前为止所拥有的...
string selections = "";
foreach (CheckBox ctrl in phProductLines.Controls.OfType<CheckBox>)
{
selections += ctrl.Text + ", ";
}
Run Code Online (Sandbox Code Playgroud)
但是我收到了错误 - "Foreach无法对方法组进行操作".
任何帮助将不胜感激.
谢谢.
例如,我需要反转文本中的所有数字组
"test text 145 for 23 site 1"
Run Code Online (Sandbox Code Playgroud)
我们需要这个输出
"test text 541 fro 32 site 1"
Run Code Online (Sandbox Code Playgroud) 我正在使用一个小型库,在运行时生成"where"表达式.我已经能够使用不同的运算符导航对象属性和查询Expression.Equal,Expression.NotEqual甚至是.Contains()字符串上的方法.
我遇到了一种情况,我需要创建一个表示链式方法的表达式,如下所示:x => x.SomeColumn.Trim().EndsWith("SomeText").我不知道从哪里开始.
我.EndsWith()已经像这样实现了这个方法:
static Expression<Func<TEntity, bool>> GetEndsWithExpression(
ParameterExpression parameterExpression,
Expression propertyExpression,
Expression valueToFind)
{
var propertyExp = propertyExpression;
var method = typeof(string).GetMethod("EndsWith", new[] { typeof(string) });
var someValue = valueToFind;
var containsMethodExp = Expression.Call(propertyExp, method, someValue);
return Expression.Lambda<Func<TEntity, bool>>(containsMethodExp, parameterExpression);
}
Run Code Online (Sandbox Code Playgroud)
我想知道你是否可以帮我弄清楚如何添加.Trim()方法并将其与.EndsWith()方法链接起来.
其他一些信息,我已经在我的项目中使用了LINQKit,所以.AsExpandable()对我来说有些熟悉.
我认为解决方案看起来像这样:
static Expression<Func<TEntity, bool>> GetTrimEndsWithExpression(
ParameterExpression parameterExpression,
Expression propertyExpression,
Expression valueToFind)
{
var propertyExp = propertyExpression;
var trimMethod …Run Code Online (Sandbox Code Playgroud) 我有一个返回对象列表的 linq 表达式。我想以漂亮的表格格式将该输出转储到控制台。
有没有办法可以实现这一点?
var timestamp = DateTime.ParseExact("20140101T000000Z", "YYYYMMDDThhmmssZ", CultureInfo.InvariantCulture);
System.FormatException was unhandled by user code
HResult=-2146233033
Message=String was not recognized as a valid DateTime.
Source=mscorlib
Run Code Online (Sandbox Code Playgroud)
这对我来说没有任何意义,因为YYYYMMDDThhmmssZISO-8601 YYYY-MM-DDThh:mm:ssZ删除了特殊格式字符.
我想检查C#Windows窗体应用程序中的Insert键的状态.这是最小的代码(不起作用;带有两个RadioButtons的表单):
using System;
using System.Windows.Forms;
using System.Windows.Input;
// Also added PresentationCore and WindowsBase refereneces
namespace InsertModeDemo1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
if (Keyboard.IsKeyToggled(Key.Insert))
radioButtonInsert.Checked = true;
else
radioButtonOverstrike.Checked = true;
}
}
}
Run Code Online (Sandbox Code Playgroud) 下面有两个linq查询,它们返回完整的差异结果,第一个查询返回4个记录,第二个返回72个记录.我认为他们是一样的.谁能解释为什么他们会返回差异记录集.谢谢你的帮助.
void Main()
{
var q1 = from c in Customers
where !c.Orders.Any(o => o.OrderDetails.Sum(od => od.UnitPrice * od.Quantity) < 1000)
select new {c.CustomerID, c.ContactName};
q1.Dump();
var q2 = from c in Customers
where c.Orders.Any(o => o.OrderDetails.Sum(od => od.Quantity * od.UnitPrice) >= 1000)
select new {c.CustomerID, c.ContactName};
q2.Dump();
}
Run Code Online (Sandbox Code Playgroud) 我一直在寻找一段时间如何编写在服务器上注册的每个玩家的详细信息列表,这样当人们登录时,他们的详细信息将从xml文件中加载,并从他们注销的地方恢复.
我知道那里有很多教程,但我似乎无法做任何工作.我需要随机访问,并实时在硬盘上更新文件.当前代码(远离工作)显示了后面的格式,但我不理解xml的大多数概念,例如什么是属性/节点/元素?教程似乎想假设你知道..
XMLFile = XDocument.Load(@"C:/users.xml");
var users = XMLFile.Descendants( "Users" );
int count = 0;
foreach ( var user in users )
{
count++;
userName[count] = user.ToString();
XElement element = (XMLFile.FirstNode as XElement);
userPass[count] = element.Value;
XAttribute attribute = (XMLFile.NextNode as XAttribute);
userLocation[count] = attribute.Value;
attribute = (XAttribute)XMLFile.NextNode;
userRotation[count] = attribute.Value;
}
Run Code Online (Sandbox Code Playgroud)
这个想法是文件将被格式化为这样(作为xml ..)
Users
Aaron
password
vector3 of location
Quaternion of Rotation
SomeoneElse
hispassword
Vector3 of location
Quaternion of rotation
//and so on....
Run Code Online (Sandbox Code Playgroud)
这些值将在客户端登录并通过网络发送其他所有工作时读取.我只是无法获得任何读取/写入xml的方法,所以感谢您的帮助.
如果我有一个类似以下的方法..
void Foo (int x, int y = 23, int z=10)
{
Console.WriteLine (x);
}
Run Code Online (Sandbox Code Playgroud)
我通过: Foo(20,30)
2个可选参数中的哪一个将获得30?
另外,如果我想将20 x和30 传递给z?
我最近一直在玩各种类型的PriorityQueue类,我遇到过一些我不太了解的行为.
这是我正在运行的单元测试的片段:
PriorityQueue<Int32> priorityQueue = new PriorityQueue<Int32>();
Randomizer r = new Randomizer();
priorityQueue.AddRange(r.GetInts(Int32.MinValue, Int32.MaxValue, r.Next(300, 10000)));
priorityQueue.PopFront(); // Gets called, and works correctly
Int32 numberToPop = priorityQueue.Count / 3;
priorityQueue.PopFront(numberToPop); // Does not get called, an empty IEnumberable<T> (T is an Int32 here) is returned
Run Code Online (Sandbox Code Playgroud)
正如我在评论中所指出的那样,PopFront()被调用并正确运行,但是当我尝试调用PopFront(numberToPop)时,该方法根本没有被调用,因为它甚至没有进入该方法.
以下是方法:
public T PopFront()
{
if (items.Count == 0)
{
throw new InvalidOperationException("No elements exist in the queue");
}
T item = items[0];
items.RemoveAt(0);
return item;
}
public IEnumerable<T> PopFront(Int32 numberToPop)
{
Debug.WriteLine("PriorityQueue<T>.PopFront({0})", numberToPop); …Run Code Online (Sandbox Code Playgroud)