Linked Questions
75 questions linked to/from All possible array initialization syntaxes
135
votes
3
answers
244k
views
Options for initializing a string array [duplicate]
What options do I have when initializing string[] object?
34
votes
7
answers
88k
views
what is [] brackets in .net? [duplicate]
i have seen [] such brackets in c# very very rarely but when i start to learn asp.net i have seen them many times but still i couldn't understand what they does ?
They are not part of code as using ...
4
votes
5
answers
43k
views
How to initialize an array of Point? [duplicate]
I need to initialize an array of three points.
I want to write it like below, but only once for three elements.
Point P = new Point { X = 0, Y = 1 };
Point[] P = new Point[3];// <---- ?
How to ...
0
votes
5
answers
6k
views
What does new [] mean [duplicate]
There is a code where that reads something from the XML and loads it into dictionary.
Pls find the code below. I need to understand what new [] {header} does.
what is new [] doing here.Thanks in ...
0
votes
3
answers
3k
views
How to return anonymous array? [duplicate]
What are the syntax rules for creating an anonymous array?
i.e.
int[] function()
{
int element1 = 1;
int element2 = 2;
return //array with element1 and element2
{
And what other uses does ...
3
votes
1
answer
2k
views
Is there any difference between new int[0] and new int[]{} [duplicate]
I want to inizialize a new int array.
What are the advantages of:
var myNewArray = new int[]{};
And:
var myNewArray = new int[0];
Which one should I prefer over the other, or is it just a matter of ...
0
votes
1
answer
7k
views
C# Fill array values in just one line of code [duplicate]
I'm adding value to an array of bytes with the following code:
byte[] ConnectionPath;
ConnectionPath[0] = 0;
ConnectionPath[1] = 2;
ConnectionPath[2] = 1;
ConnectionPath[3] = 0;
My question is, can't ...
0
votes
2
answers
3k
views
Array without fixed size [duplicate]
I started studying C# a while back, and I always heard that if I do not have the size of the array, I should always choose list, because arrays can't be initialized without the size.
That being said, ...
0
votes
2
answers
7k
views
How can I pass a byte value in c# function [duplicate]
I have this function in c#:
public string CommitDocument(string extension, byte[] fileBytes)
{
// some code here
}
I'm trying to call this function like this:
CommitDocument("document.docx", ...
-2
votes
3
answers
4k
views
Declare an array of queues [duplicate]
What is the language grammatical problem in my code?
I want to declare an array of queues. Is this the right way to declare and use them?
public static void Main(string[] args)
{
...
0
votes
2
answers
2k
views
Define and set an array property with a single element [duplicate]
I have a class as follows, its for an API so it must be in this format
public class Command
{
public string response_type { get; set; }
public string text { get; set; }
public Attachment[]...
-1
votes
1
answer
4k
views
Assign a GUID in C# [duplicate]
I have a string representation of the Guid,I'm doing some testing and I'm hard-coding some GUIDs into the code. The below way can assign Guid of single value.
Guid g = new Guid("11223344-5566-...
0
votes
1
answer
1k
views
How to give an array C# property a default value? [duplicate]
So I know with normal properties you can give it a default value eg.
public int someMethod { get; } = 1;
So my question is it possible to do the same with an array property?
public int[] someMethod {...
-3
votes
1
answer
1k
views
Is there a way to declare a float array with a fixed int size? [duplicate]
Is there a way to declare a array that contains float variables and that has a fixed size of an int?
int balls = 5;
float array posX[balls];
private float posY[] = 0;
basically, I want to create an ...
-1
votes
2
answers
386
views
Difference between using new in arrays in C# [duplicate]
What will be the difference between using keyword new in declaring a new array or not using it? I saw something like that on the internet but didn't fully understand the difference:
new keyword on the ...