All Questions
18 questions
55
votes
5
answers
206k
views
What's the use of .Any() in a C# List<>?
I've been discussing this with colleagues, and we couldn't figure out what the use is of .Any for any given List<>, in C#.
You can check the validity of an element in the array like the ...
22
votes
3
answers
85k
views
Should I use a list or an array?
I'm working on a windows form to calculate UPC for item numbers.
I successfully create one that will handle one item number/UPC at a time, now I want to expand and do it for multiple item numbers/...
17
votes
4
answers
6k
views
size_t or int for dimensions, index, etc
In C++, size_t (or, more correctly T::size_type which is "usually" size_t; i.e., a unsigned type) is used as the return value for size(), the argument to operator[], etc. (see std::vector, et. al.)
...
9
votes
3
answers
9k
views
Ordered enumeration: IEnumerable or Array (in C#)?
Typical context: I make an extension method for a collection which considers that the elements are ordered. The function starts at the beginning, at index 0, and the order has significance. Examples: ...
8
votes
2
answers
6k
views
CA1819: Properties should not return arrays. Does this happen only with arrays? If yes, why?
I have a question about CA1819 msdn performance warning.
The rule is: Arrays returned by properties are not write-protected, even if the property is read-only. To keep the array tamper-proof, the ...
5
votes
2
answers
520
views
Which design pattern is illustrated by inheriting IStructuralComparable interface?
We know that some design patterns are found so useful that they become features of the language itself.
For instance, the interface IEnumerator which is implemented by Array object.
This helps in ...
4
votes
2
answers
3k
views
Data structure for grid with negative indeces
Sorry if this is an insultingly obvious concept, but it's something I haven't done before and I've been unable to find any material discussing the best way to approach it.
I'm wondering what's the ...
3
votes
1
answer
2k
views
The array class in C# - Implementation questions
I am studying the Array class in C#. The following is the implementation of System.Array class:
[SerializableAttribute]
[ComVisibleAttribute(true)]
public abstract class Array : ICloneable, IList, ...
2
votes
1
answer
1k
views
Beginners C# question about Array.Reverse
I am sitting through a very well-explained and thorough video tutorial series, using Visual Studio 2012 as my developing environment.
Anyway, one thing that is hard to figure out is this. Say you ...
2
votes
2
answers
558
views
.Net speed vs Custom Code speed
In an int?[] garunteed to have original values, I wanted to find the index of null, which will only be a single index.
I drilled into the Array.IndexOf(T[] array, T value) .NET and, after all of the ...
2
votes
3
answers
3k
views
Building a simple AI for Noughts & Crosses game
I'm developing a simple noughts & crosses game where the player plays against the computer.
Obviously, I use the Randomize function of the language, however, the final stage of refinement is to ...
2
votes
1
answer
918
views
Accessing a private array when I have an extension method
I'm trying to make a number of data classes for my C#/XNA game, which would essentially be a wrapper around T[,]:
public interface IGrid<T>
where T : struct
{
Point Size { get; }
T ...
1
vote
4
answers
4k
views
immutable string in array, reference type vs value type
Trying to understand strings better in C#
Are these assertions correct?
string is immutable
string is reference type but behaves like value type
For these code samples...
string x = "one"
(...
1
vote
0
answers
42
views
is it better to have tracking fields that are maintained separately for arrays? [duplicate]
I wasn't sure exactly how to word this question, but basically, I have a struct stNeuralLayers (for a neural network I'm playing around with) with fields that are matrices (such as a double[,] ...
1
vote
0
answers
630
views
Given a two-dimensional array what is there a good way to identify distinct regions of elements?
I am generating a 2D "world map" in Unity which I use C# and Perlin noise for.
I have a Tile object that holds the graphic of the tile and position. There are a few more attributes to this class, ...