小编Rob*_*ini的帖子

可以将Byte []数组写入C#中的文件吗?

我正在尝试写出一个Byte[]表示文件完整文件的 数组.

来自客户端的原始文件通过TCP发送,然后由服务器接收.接收到的流被读取到一个字节数组,然后被发送以由该类处理.

这主要是为了确保接收TCPClient为下一个流做好准备并将接收端与处理端分开.

所述FileStream类不采取一个字节数组作为参数或另一个流对象(它允许你写字节到它).

我的目标是通过与原始(使用TCPClient的线程)不同的线程完成处理.

我不知道如何实现这个,我该怎么办?

.net c#

329
推荐指数
6
解决办法
36万
查看次数

C#Generics有性能优势吗?

我有许多代表各种实体的数据类.

哪个更好:使用泛型和接口编写泛型类(比如打印或输出XML),或者编写一个单独的类来处理每个数据类?

是否有性能优势或任何其他好处(除了节省我编写单独课程的时间)?

.net c# generics performance

37
推荐指数
6
解决办法
2万
查看次数

如何解析图像标记的HTML字符串以获取SRC信息?

目前我使用.Net WebBrowser.Document.Images()来做到这一点.它需要Webrowser加载文档.它很乱,占用资源.

根据这个问题, XPath优于正则表达式.

任何人都知道如何在C#中做到这一点?

.net html c# regex xpath

25
推荐指数
2
解决办法
4万
查看次数

LINQ-组合多个列表<T>并按值排序(.Net 3.5)

我正在尝试组合一些List<T> where T:IGetTime(即T总是有方法getTime()).

然后我想为了通过项目DateTimegetTime()返回.

我的LINQ看起来像这样:

public static List<T> Combine(List<T> one, List<T> two, List<T> three)
    {
        var result = from IGetTime item in one
                     from IGetTime item2 in two
                     from IGetTime item3 in three
                     select new{ item, item2, item3 };

        return result.ToList();
    }
Run Code Online (Sandbox Code Playgroud)

我还没有补充一下orderby.哪个应该看起来像这样:

var thestream = from T item in this
                orderby item.getTime() descending
                select item;
Run Code Online (Sandbox Code Playgroud)

无论如何都要结合并订购最终清单????

提前致谢,

罗伯托

.net c# linq generics

21
推荐指数
1
解决办法
3万
查看次数

ASP.NET Web API - 没有"MediaTypeFormatter"可用于读取"Int32"类型的对象

我不完全确定这里发生了什么.我可能在某处弄乱了,但我不知道是什么.

我的API控制器方法如下所示:

public HttpResponseMessage<string> Put(int id)
Run Code Online (Sandbox Code Playgroud)

我也试过一个字符串也有同样的错误.

有任何想法吗?

谢谢.

编辑:要清楚 - id是路由参数.请求的主体是JSON.如果我删除route参数,该方法将正常运行.

c# asp.net asp.net-web-api

16
推荐指数
3
解决办法
6万
查看次数

是否可以在.Net 3.5中进行通用控制?

我声明了以下Generic usercontrol:

public partial class MessageBase<T> : UserControl
    {
        protected T myEntry;
        public MessageBase()
        {
            InitializeComponent();
        }
        public MessageBase(T newEntry)
        {
            InitializeComponent();
            myEntry = newEntry;
        }    
    }
}
Run Code Online (Sandbox Code Playgroud)

但编译器不允许我这样做:

public partial class MessageControl : MessageBase<Post>
{
    public MessageControl()
    {
        InitializeComponent();
    }
}
Run Code Online (Sandbox Code Playgroud)

如何在C#中创建通用用户控件?

.net c# generics user-controls winforms

10
推荐指数
1
解决办法
6649
查看次数

SQL Azure数据库命名管道错误

直到昨晚,我的网站(由DiscountASP.net托管)和它连接的SQL Azure数据库正常运行.

出于某种原因,在夜间,该网站因命名管道错误而关闭.错误40.

在连接字符串中使用"tcp:"作为服务器名称前缀,现在出现错误:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 0 - A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.)
Run Code Online (Sandbox Code Playgroud)

因此,为了清楚起见,web.config文件在网站上次工作的时间和命名管道错误的项目之间根本没有变化.

现在,用户名,密码和实例名称都是正确的,因为该站点完全针对远程SQl Azure服务器本地运行. …

sql iis-7 azure-sql-database

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

有没有办法从String创建SyndicationFeed?

我正在尝试从本地存储的XML数据重新创建SyndicationFeed对象(System.ServiceModel.Syndication).

如果我使用XMLDocument,这将很容易.我会调用LoadXml(字符串).

SyndicationFeed只会从XMLReader加载.XMLReader只接受Stream或其他XMLReader或TextReader.

由于XMLDocument将加载一个字符串,我试图按如下方式(以扩展方法的形式)执行此操作:

    public static SyndicationFeed ToSyndicationFeed(this XmlDocument document)
    {
        Stream thestream = Stream.Null;
        XmlWriter thewriter = XmlWriter.Create(thestream);

        document.WriteTo(thewriter);

        thewriter.Flush();
        XmlReader thereader = XmlReader.Create(thestream);

        SyndicationFeed thefeed = SyndicationFeed.Load(thereader);

        return thefeed;
    }
Run Code Online (Sandbox Code Playgroud)

我不能让这个工作.即使XMLDocument填充了要加载到SyndicationFeed中的Feed,Stream也始终为空.

您可以提供任何帮助或指示将是最有帮助的.

谢谢,罗伯托

.net c# linq syndicationfeed

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