小编Aka*_*shi的帖子

SocketAsyncEventArgs示例中缺少AsyncUserToken类:如何使示例工作?

我正在研究TCP多线程服务器和客户端.我从Microsoft网站上找到了一些代码:http: //msdn.microsoft.com/en-us/library/system.net.sockets.socketasynceventargs.aspx

但是我收到以下错误:

找不到类型或命名空间名称'AsyncUserToken'(您是否缺少using指令或程序集引用?)

即使我在谷歌上搜索它,我也无法找到要包含的命名空间,以下是我目前拥有的:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;
Run Code Online (Sandbox Code Playgroud)

感谢帮助.

.net c# sockets tcp

5
推荐指数
2
解决办法
3370
查看次数

在Android中使用HttpURLConnection的apk文件的FileNotFoundException

            URL url = new URL(arg0[1]);
            HttpURLConnection c = (HttpURLConnection) url.openConnection();
            c.setRequestMethod("GET");
            c.setDoOutput(true);
            c.connect();

            String PATH = "/mnt/sdcard/Android/";
            File file = new File(PATH);
            file.mkdirs();
            File outputFile = new File(file, "myGame.apk");
            if(outputFile.exists()){
                outputFile.delete();
            }
            FileOutputStream fos = new FileOutputStream(outputFile);

            InputStream is = c.getInputStream();

            byte[] buffer = new byte[1024];
            int len1 = 0;
            while ((len1 = is.read(buffer)) != -1) {
                fos.write(buffer, 0, len1);
            }
            fos.close();
            is.close();

            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.fromFile(new File("mnt/sdcard/Android/myGame.apk")), "application/vnd.android.package-archive");
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intent);
Run Code Online (Sandbox Code Playgroud)

我想做自动更新应用程序功能,它将下载apk文件并安装它.但是当我通过Java下载和异常捕获:java.io.FileNotFoundException http://192.168.2.143/myGame.apk,其中url [0] ="http://192.168.2.143/myGame.apk",我在我的设备中使用浏览器打开http://192.168.2.143/myGame.apk …

java android

5
推荐指数
1
解决办法
1155
查看次数

使用C#在SQL中使用空格

我有一个用C#编写的Windows应用程序,它连接到SQL数据库.

我的应用程序中有文本字段,并像这样更新数据库:

string name = textBox60.Text;

string sql = "insert into myTable(Name) values ('" + name + "')";
DbHelper.ExecuteNonquery(sql);

public static int ExecuteNonquery(string sql)
    {
        using (SqlConnection cn = new SqlConnection(constr))
        {
            if (cn.State == ConnectionState.Closed)
            {
                cn.Open();
            }
            else if (cn.State == ConnectionState.Open)
            {
                cn.Close();
                cn.Open();
            }
            else if (cn.State == ConnectionState.Broken)
            {
                cn.Close();
                cn.Open();
            }
            using (SqlCommand cm = new SqlCommand(sql, cn))
            {
                return cm.ExecuteNonQuery();
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

但是对于数据库中具有类型的每个数据nchar,它们都充满了空白.例如,如果我在文本字段中填写abc,当我检查数据库时,它将成为"abc___________________"(白色空格)这样的东西.

如何防止这种情况,除了在我阅读它们时修剪字符串,或者如果我有大量此类数据则使用UPDATE数据SET …

c# sql whitespace

2
推荐指数
2
解决办法
2391
查看次数

将斜杠添加到字符串

我想替换这样的字符串

'10001'
Run Code Online (Sandbox Code Playgroud)

\'10001\'
Run Code Online (Sandbox Code Playgroud)

以下代码不起作用:

Console.WriteLine(content);
content.Replace("'", "\\'");
Console.WriteLine(content);
Run Code Online (Sandbox Code Playgroud)

甚至这个:

Console.WriteLine(content);
content.Replace("'", "\\\\'");
Console.WriteLine(content);
Run Code Online (Sandbox Code Playgroud)

content之前和之后的值完全相同replace,即'10001'

我正在使用VC#2010 Express.感谢帮助.

c# string

-1
推荐指数
1
解决办法
1247
查看次数

标签 统计

c# ×3

.net ×1

android ×1

java ×1

sockets ×1

sql ×1

string ×1

tcp ×1

whitespace ×1