小编use*_*899的帖子

C# 属性数组

我有几个 get 属性,我希望它们能够像函数数组一样循环。我希望能够做这样的事情

public int prop1 { get; }
public string prop2 { get; }
public int[] prop3 { get; }
public int prop4 { get; }
public string prop5 { get; }
public string prop6 { get; }

Func<var> myProperties = { prop1, prop2, prop3, prop4, prop5, prop6 };

ArrayList myList = new ArrayList();
foreach( var p in myProperties)
{
    myList.Add(p);
}
Run Code Online (Sandbox Code Playgroud)

这段代码非常糟糕,但我认为它传达了我想要做的事情的想法。有谁知道我怎么能做到这一点?

c# arrays getter properties

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

当文件太大时,C#HttpWebResponse contentlength = -1

我从烂番茄网站获得了json格式的字符串.我的代码看起来像

HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create(url);
webRequest.Method = "GET";
webRequest.ContentType = "application/json";

HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();

using(StreamReader reader = new StreamReader(response.GetResponseStream()))
{
    //Code I'm using the reader with
}
Run Code Online (Sandbox Code Playgroud)

当我运行一个返回1-4电影的电影搜索时它工作正常.但是,如果我尝试获得5或更多的结果,它将无法正常工作.webResponse内容长度为-1.当我返回4部电影的结果时,内容长度为7,449.

c# httpwebrequest httpwebresponse

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

C#收到错误.无法将System.Data.DataRow转换为DataRow

我收到了这个错误

"Error  8   Cannot implicitly convert type 'System.Collections.Generic.List<System.Data.DataRow>' to 'System.Collections.Generic.List<DataRow>'
Run Code Online (Sandbox Code Playgroud)

"

产生问题的代码行是这个......

List<DataRow> dRowList = target.SearchFor(searchPhrase, searchField, matchesAny);
Run Code Online (Sandbox Code Playgroud)

target.SearchFor返回DataRow列表.我无法弄清楚出了什么问题.

c# datarow implicit

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