我有一个2D阵列a[3,3].如何将一个维度表示为一个新数组并将其传递给某个函数?
int[,] a = new int[3,3];
a[0,0] = 1;
...
string b = concatenate(a[0]); // where concatenate is a function
// take a one dimension array as param
Run Code Online (Sandbox Code Playgroud)
另外,我可以使用C#创建65000x65000阵列吗?我得到了一些"内存不足"的错误.
我在我的应用程序中使用protobuf-net进行序列化/反序列化.我正面临一个问题.
[ProtoContract()]
ClsTest
{
private bool _isPeriodic
[ProtoMember(1)]
public bool IsPeriodic
{
get
{
return _isPeriodic;
}
set
{
isPeriodic = value;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我在我的collction对象中使用这个类.
序列化过程工作正常,但在反序列化后,默认情况下,属性IsPeriodic的值为true,尽管在某些情况下它是错误的.谁能帮我?
假设我有List<Stuff> listA一些内容.我创建了第二个列表如下:
List<Stuff> listB = new List<Stuff>(listA);
Run Code Online (Sandbox Code Playgroud)
假设我有一个项目listA,我尝试将其删除listB:
Stuff itemFromA = listA[0];
listB.Remove(itemFromA);
Run Code Online (Sandbox Code Playgroud)
假设Stuff是一个类,是否应该成功删除该项listB?换句话说,成员是相同的对象还是创建新列表的过程克隆项目?
我在一些代码中遇到行为我正在调试.Remove无法从中删除项目listB.
我试图抓住这个网站的所有<entry>标签.它会加载到XDocument中,但我似乎无法抓住任何元素.这是我的代码:<entry>
XDocument netflixPage = new XDocument();
netflixPage = XDocument.Load("http://odata.netflix.com/Catalog/Titles");
foreach (XElement xe in netflixPage.Descendants("entry").ToList())
{
string movieInfo = xe.Value;
}
Run Code Online (Sandbox Code Playgroud) "\n \n Expected:\n \n \n Q4\n \n \n 2011\n \n "
Run Code Online (Sandbox Code Playgroud)
从该字符串,我需要得到以下内容:
"Expected Q4 2011"
Run Code Online (Sandbox Code Playgroud)
我尝试了以下,没有骰子:
myString.Trim().Replace("\n", "");
Run Code Online (Sandbox Code Playgroud)
我得到以下内容(大量的空白是故意的,而不是网站格式化问题.实际上是返回的内容.)
"Expected: Q4 2011"
Run Code Online (Sandbox Code Playgroud) 我只是想知道它是否可能..
我有一个基类,有一个名为Level的变量.然后我从中派生出一个类,但这里的Level应该叫做Points.
有没有办法在派生类中重命名Level变量?
编辑 - 请原谅我将属性称为变量.我对编程非常陌生,尤其是课程(我们的老师因某些原因没有教我们)
我目前正在尝试理解每像素碰撞检测.
这是我不明白的代码:
static bool IntersectPixels(Rectangle rectangleA, Color[] dataA,
Rectangle rectangleB, Color[] dataB)
{
// Find the bounds of the rectangle intersection
int top = Math.Max(rectangleA.Top, rectangleB.Top);
int bottom = Math.Min(rectangleA.Bottom, rectangleB.Bottom);
int left = Math.Max(rectangleA.Left, rectangleB.Left);
int right = Math.Min(rectangleA.Right, rectangleB.Right);
// Check every point within the intersection bounds
for (int y = top; y < bottom; y++)
{
for (int x = left; x < right; x++)
{
// Get the color of both pixels at this point
Color …Run Code Online (Sandbox Code Playgroud) 我有一个字符串数组,如下所示:
string[] userFile = new string[] { "JohnDoe/23521/1", "JaneDoe/35232/4", ... };
Run Code Online (Sandbox Code Playgroud)
我正在尝试以下但这只会返回完全匹配.如果我正在寻找"23521",我希望能够返回一场比赛.
var stringToCheck = "23521";
if (userFile.Any(s => stringToCheck.Contains(s)))
{
// ...
Run Code Online (Sandbox Code Playgroud) 我有大约50000个XML文件,每个文件的大小为50KB.我想在这些文件中搜索数据,但到目前为止我的解决方案非常慢.有没有办法提高搜索性能?
我有一个像这样的字符串:
"(33) 3669-0210 Gerencia"
Run Code Online (Sandbox Code Playgroud)
我试图获得之后/之前的所有数字 - (连字符),直到在C#中使用Regex在两端找到一个空格.
输出应该是
"3669-0210"
Run Code Online (Sandbox Code Playgroud)
有人可以帮助使用可在C#中运行的Regex表达式吗?