在Java中我们可以做类似的事情
final string str = "I am a string";
Thread thread = new Thread(...{
string str2 = "bla bla bla " + str;
});
Run Code Online (Sandbox Code Playgroud)
我不完全理解如何做到这一点,但重点是我需要声明str为最终在我的线程中访问它所以没有可变的腐败.
但现在我如何在C#中做到这一点
string str = "I am a string";
Task.Run(() => {
string str2 = "bla bla " + str;
});
Run Code Online (Sandbox Code Playgroud)
它确实有效,但我不确定这是否正确.我正在使用Visual Studio for Xamarin.
我需要一种算法,它可以在List中使用任意数量的List并生成一组唯一的排列.我更喜欢找到LINQ解决方案.
我实际上有一个运行良好的Javascript函数,我正在尝试用C#重新创建它(参见底部的代码)
C#(我的尝试) - Visual Studio不喜欢我的第二个Aggregate().它说 the arguments cannot be inferred from usage
public static void testit()
{
List<List<string>> master = new List<List<string>>();
List<string> voltages = new string[] { "208", "230", "460" }.ToList();
List<string> sysConfigs = new string[] { "10205", "10210", "10215", "10220" }.ToList();
master.Add(voltages);
master.Add(sysConfigs);
var amp = master.Aggregate(
(a, b) => a.Aggregate(
(r, v) => r.Concat(
b.Select(w => new List<string>().Concat(v, w))
), new List<string>()
)
);
}
Run Code Online (Sandbox Code Playgroud)
这个新集合的输出应该如下所示:
/*
OUTPUT (displayed as arrays - but will be lists): …Run Code Online (Sandbox Code Playgroud) 如何与后台线程一起维护前台线程.如果我尝试在工作中将项添加到列表中,它会给我一个跨线程异常.
我的DataGridView.DataSource有问题,它耗费了我很多时间来解决这个问题.以下是代码:
string[] queryWords = singleQuery.Split(' '); // Split the query words according the "space" character
// Compose the SQL select query
string selectClause = @"SELECT ID, CategoryID, Name, UnitID, Price, QuantityAgen, QuantityBanjer, QuantityMalalayang, QuantitySorong FROM Product WHERE ";
// Add the where clauses inside the SQL select query
for (int i = 0; i < queryWords.Length; i++)
{
selectClause += "(Name LIKE '%" + queryWords[i] + "%')";
if (i < queryWords.Length - 1)
selectClause += " AND ";
}
// …Run Code Online (Sandbox Code Playgroud) 是否可以使用Between with Max,如下所示:
SELECT * FROM TABLE WHERE ID BETWEEN 100 AND MAX
Run Code Online (Sandbox Code Playgroud)
还是一种走到尽头的方法?
我想将数据从 DataGridView 传输到另一个,这是我的代码示例:
private void btnShow(object sender, EventArgs e)
{
DataTable dtr = new DataTable();
dtr.Columns.Add(new DataColumn("Name", typeof(string)));
dtr.Columns.Add(new DataColumn("Label", typeof(string)));
dtr.Columns.Add(new DataColumn("Domain", typeof(string)));
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
DataRow erow = dtr.NewRow();
erow[0] = dataGridView1.Rows[i].Cells[0].Value.ToString();
erow[1] = dataGridView1.Rows[i].Cells[1].Value.ToString();
erow[2] = dataGridView1.Rows[i].Cells[2].Value.ToString();
dtr.Rows.Add(erow);
}
dataGridView2.DataSource = dtr;
}
Run Code Online (Sandbox Code Playgroud)
我还在NullReferenceException11 号线收到。
c# ado.net exception-handling datagridview nullreferenceexception
我想用
XmlReader.Create(aString);
Run Code Online (Sandbox Code Playgroud)
阅读XML.但是这个aString中有很多"\",导致错误:
路径中的非法字符.
所以我想替换所有"\"带"".
我试过了:
aString.Replace("\", "");
aString.Replace("\\", "");
aString.Replace(@"\", "");
aString.Replace(@"\", string.Empty);
Run Code Online (Sandbox Code Playgroud)
它们都不起作用.
我有一个31-10-2014字符串,我想与数据库中的值进行比较.
public ActionResult SearchResult(string searchDate)
{
var bookings = from m in db.Bookings
select m;
if (!String.IsNullOrEmpty(searchDate))
{
bookings = bookings.Where(s => s.Date1.CompareTo( DateTime.ParseExact(searchDate, "dd-mm-yyyy", CultureInfo.InvariantCulture)) >= 0);
}
return View(bookings);
}
Run Code Online (Sandbox Code Playgroud)
比较保持失败,我应该如何将输入日期与数据库值进行比较(我将try catch用于验证输入是数据时间,因此示例更清晰)
我收到消息(即使没有searchData):
Linq无法识别ParseExact方法.
我有这个对象数组调用blocks,我希望数组中的每个对象都通过一个函数.
这是我的代码......
object[] blocks = new object[2];
blocks[0] = block;
blocks[1] = block1;
blocks[2] = block2;
if (player.Bottom >= screen.Bottom)
{
jump = false;
jumped = false;
}
else if (player.Right >= i.Left + 5 &&
player.Left <= i.Right - 5 &&
player.Bottom >= i.Top &&
player.Bottom <= i.Bottom - 10)
{
force = 0;
jump = false;
player.Top = i.Location.Y - player.Height;
}
else
{
player.Top += 5;
jumped = false;
nothing = false;
}
Run Code Online (Sandbox Code Playgroud)
我想知道如何替换i …
基本上我正在寻找的是一些方法来查找通道名称,如公告,并向其发送消息.我知道无论何时用户通过不一致发送消息或者如果事件发生在不和谐中,如何发送消息
e.Server.FindChannels("Channel Name").FirstorDefault;
await channel.sendmessage(string.Format("Message"))
Run Code Online (Sandbox Code Playgroud)
但我希望在Twitch上发生事件时发送消息.
我目前的代码是这样的:
TwitchAPIexample.RootObject json = TwitchAPIexample.BuildConnect();
if (TwitchAPIexample.TwitchLive(json))
{
var channel = client.GetChannel("announcements"); //Where I need to get channel
//Where I need to send message to channel
}
Run Code Online (Sandbox Code Playgroud)
我从中提取代码的文件:
using System.Net;
using System.IO;
using Newtonsoft.Json;
namespace MyFirstBot.Plugins
{
public class TwitchAPIexample
{
private const string url = "https://api.twitch.tv/kraken/streams/channel";
public bool isTwitchLive = true;
public static RootObject BuildConnect()
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "Get";
request.Timeout = 12000;
request.ContentType = "application/json";
request.Headers.Add("authorization", "Token");
using (System.IO.Stream …Run Code Online (Sandbox Code Playgroud) c# ×9
arrays ×2
datagridview ×2
linq ×2
ado.net ×1
between ×1
datasource ×1
datetime ×1
discord ×1
discord.net ×1
ienumerable ×1
max ×1
permutation ×1
replace ×1
sql-server ×1
string ×1
t-sql ×1
twitch ×1
xamarin ×1