using Microsoft.VisualBasic;
Microsoft.VisualBasic.Interaction.InputBox("Favourite RPG?", "Game", "Cool!");
Run Code Online (Sandbox Code Playgroud)
那么这样做基本上就是询问用户他们最喜欢的RPG.然后它显示默认值.我知道这是一个小例子,但我的程序不会运行,因为我收到此错误:
The type or namespace name 'Interaction' does not exist in the namespace 'Microsoft.VisualBasic' (are you missing an assembly reference?)
Run Code Online (Sandbox Code Playgroud)
最初我在这里发现了这个
我正在尝试制作一个可以在c#中填充int数组的算法.基本上,作为MS Paint中的填充工具,我有一个颜色,如果我在数组中选择(x,y)坐标,它会用新颜色替换所有具有相同初始颜色的邻居.
例如:
[0,0,0]
[0,1,0]
[1,1,0]
Run Code Online (Sandbox Code Playgroud)
如果我将3放入(0,0),则数组变为:
[3,3,3]
[3,1,3]
[1,1,3]
Run Code Online (Sandbox Code Playgroud)
所以我在递归中尝试了它,它确实有效,但不是所有时间.实际上,我有时会出现"Stack Overflow"错误(似乎合适).这是我的代码,如果你能告诉我什么是错的话会很棒:)
public int[,] fill(int[,] array, int x, int y, int initialInt, int newInt)
{
if (array[x, y] == initialInt)
{
array[x, y] = newInt;
if (x < array.GetLength(0) - 1)
array = fill(array, (x + 1), y, initialInt, newInt);
if (x > 0)
array = fill(array, (x - 1), y, initialInt, newInt);
if (y < array.GetLength(1) - 1)
array = fill(array, x, (y + 1), initialInt, newInt);
if (y …Run Code Online (Sandbox Code Playgroud) 我有传入的数据,需要分成多个值...即.
2345 \n564532 \n345634 \n234 234543 \n1324 2435 \n
当我收到它时,长度是不一致的,当它存在时间距是不一致的,我想分析每个\n之前的最后3位数.如何断开字符串并将其转换为新字符串?就像我说的,这一轮,它可能有3个\n命令,下一次,它可能有10个,我如何创建3个新字符串,分析它们,然后在接下来的10个进入之前销毁它们?
string[] result = x.Split('\r');
result = x.Split(splitAtReturn, StringSplitOptions.None);
string stringToAnalyze = null;
foreach (string s in result)
{
if (s != "\r")
{
stringToAnalyze += s;
}
else
{
how do i analyze the characters here?
}
}
Run Code Online (Sandbox Code Playgroud) 我在OSX上使用Xamarin(mono 3.2.5)创建一个C#控制台应用程序,该应用程序连接到blockchain.info websocket流。我已经包含了NuGet的socketio4net库,并认为我正确地遵循了规范,但是对于socket.io连接,我一般还是有些陌生,所以请纠正我的错误。调用下面的socket.Connect()方法后,我立即收到错误消息。
我创建了一些这样的事件处理程序:
static void SocketOpened(object sender, EventArgs e)
{
Console.WriteLine ("opened event handler");
Console.WriteLine (e.ToString());
}
static void SocketError(object sender, SocketIOClient.ErrorEventArgs e)
{
Console.WriteLine ("error event handler");
Console.WriteLine (e.Message);
}
static void SocketMessage(object sender, MessageEventArgs e)
{
Console.WriteLine ("message event handler");
Console.WriteLine (e.Message);
}
Run Code Online (Sandbox Code Playgroud)
我的代码如下:
var socket = new Client (@"ws://ws.blockchain.info:8335/inv");
socket.Opened += SocketOpened;
socket.Error += SocketError;
socket.Message += SocketMessage;
socket.Connect ();
Console.WriteLine ("handshake: " + socket.HandShake.ErrorMessage);
socket.On("connect", (fn) => {
Console.WriteLine("On.connect msg: " + fn.MessageText);
});
socket.On …Run Code Online (Sandbox Code Playgroud) 尝试通过StreamReader将800MB文本文件加载到DataTable时,我遇到了OutOfMemory Exceptions.我想知道是否有办法从内存流中批量加载DataTable,即从StreamReader读取文本文件的前10,000行,创建DataTable,使用DataTable执行某些操作,然后将下10,000行加载到StreamReader中等等.
我的谷歌在这里不是很有帮助,但似乎应该有一个简单的方法来做到这一点.最后,我将使用SqlBulkCopy将DataTables写入MS SQL数据库,因此如果有一种比我描述的更简单的方法,我会感谢快速指向正确的方向.
编辑 - 这是我正在运行的代码:
public static DataTable PopulateDataTableFromText(DataTable dt, string txtSource)
{
StreamReader sr = new StreamReader(txtSource);
DataRow dr;
int dtCount = dt.Columns.Count;
string input;
int i = 0;
while ((input = sr.ReadLine()) != null)
{
try
{
string[] stringRows = input.Split(new char[] { '\t' });
dr = dt.NewRow();
for (int a = 0; a < dtCount; a++)
{
string dataType = dt.Columns[a].DataType.ToString();
if (stringRows[a] == "" && (dataType == "System.Int32" || dataType == "System.Int64"))
{
stringRows[a] …Run Code Online (Sandbox Code Playgroud) 看到解决方案的评论 - 文件在错误的地方
我到处寻找答案,但我找不到答案.这对我来说真的很令人沮丧,因为我从来没有从使用任何其他编程语言的文件中读取这么多麻烦.
我正在尝试从文本文件中提取用户名和密码,以获得基本的即时消息程序.我不打算发布所有代码 - 它太长了,而且很可能不相关,因为文本文件是在程序的最开始读取的.
这是我试图读取的文本文件("users.ul")的内容:
admin.password
billy.bob
sally.sal
Run Code Online (Sandbox Code Playgroud)
以下是从文本文件中读取的代码:
users = new Dictionary<string, User>();
System.Console.WriteLine("users.ul exists: " + File.Exists("users.ul"));
// Check the status of users.ul. If it exists, fill the user dictionary with its data.
if (File.Exists("users.ul"))
{
// Usernames are listed first in users.ul, and are followed by a period and then the password associated with that username.
StreamReader reader = new StreamReader("users.ul");
string line;
int count = 0;
while ((line = reader.ReadLine()) != null)
{ …Run Code Online (Sandbox Code Playgroud) 如何检查是否XElement具有Record&INVID属性?我的函数只返回单个XElement.即
<INVENTORY>
<Record>
<INVID>1315</INVID>
<INVNAME>TEST LOCATIONTEST</INVNAME>
<HOSPNAME>TEST LOCATION</HOSPNAME>
<INVTYPE>CLINICAL</INVTYPE>
<INVDT>2013-09-30T09:30:00</INVDT>
<INVDEF>YES</INVDEF>
<INVACT>YES</INVACT>
<UPDDTTM />
<UPDUSR />
<ENBREF>true</ENBREF>
<INVPWD>101315</INVPWD>
</Record>
</INVENTORY>
XElement xInventory = GetDefaultInventory();
bool hasInventory = xInventory.Elements("INVID").Any(); //What to do here ?
if (hasInventory)
{
//TO DO Some action
}
Run Code Online (Sandbox Code Playgroud) 我有一个进程在随机位置上运行大量任务,Array并希望通过使用多线程来加快速度.
它本质上做的是随机化"阵列"中的位置,检查其近似环境的值,并在满足一些特定条件时改变随机位置值.
是否有可能运行像
Parallel.For(0, n, s => { });
Run Code Online (Sandbox Code Playgroud)
循环而不是下面显示的while代码块来优化这个函数,一个代码块怎么样呢?
我一直在考虑为所选元素使用一些"忙"属性,但这实际上使得问题可能需要更加复杂.
public void doStuffTothisArray(ref int[,,] Array, ref IGenerator randomGenerator, int loops)
{
int cc = 0;
int sw = 0;
do
{
if (doStuffOnRandomPositions(ref Array, ref randomGenerator))
sw++; //if stuff was made counter
if ((cc % (loops / 10)) == 0)
Console.Write("{0} % \t", (cc / (loops / 10)) * 10); //some loading info
cc++; //count iterations
} while (cc < loops);
Console.WriteLine("Stuff altered in {0} iterations: {1}", …Run Code Online (Sandbox Code Playgroud) 我正在ASP.net中开发一个Web应用程序,它需要登录名和密码.
我想记录正在访问此Web应用程序的客户端的IP地址和计算机名称.
我正在使用log4net进行日志记录.
我尝试过这段代码,但是在使用IIS-7而不是客户机名称部署此Web应用程序后,我在日志中获得了Server Machine HostName.
Login Page Page_Load 方法:
protected void Page_Load(object sender, EventArgs e)
{
log4net.GlobalContext.Properties["Hostname"] = Dns.GetHostName();
}
Run Code Online (Sandbox Code Playgroud)
Web.Config更改:
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %property{Hostname} [%thread] %-5level %logger - %message%newline" />
</layout>
Run Code Online (Sandbox Code Playgroud)
这是一个非常庞大的项目,所以请建议我在Code中记录客户端IP地址和机器名的最小变化.
我有这个功能从文本中提取所有单词
public static string[] GetSearchWords(string text)
{
string pattern = @"\S+";
Regex re = new Regex(pattern);
MatchCollection matches = re.Matches(text);
string[] words = new string[matches.Count];
for (int i=0; i<matches.Count; i++)
{
words[i] = matches[i].Value;
}
return words;
}
Run Code Online (Sandbox Code Playgroud)
我想从返回数组中排除单词列表,单词列表看起来像这样
string strWordsToExclude="if,you,me,about,more,but,by,can,could,did";
Run Code Online (Sandbox Code Playgroud)
如何修改上述函数以避免返回列表中的单词.