This question already has answers here:
Does C# support a variable number of arguments, and how?
(4 answers)
Closed 5 years ago.
I'm trying to pass a variable number of arguments here.
Codification codebook = new codification(data,"Attr1","Attr2",..."AttrnumOfAttrColumns,"Result")
and also here:
int[][] inputs = symbols.ToJagged<int>("Attr1","Arrt2",..."AttrnumOfAttrColumns);
I was trying to do it with a for loop which is not the right.Is there a way to do this?
Codification codebook = new Codification(data, for (int i = 0; i < numOfAttrColumns; i++) {return "Attr"+Convert.ToString(i) }, "Result");
According to Accord.net manual
You can put
Codification codebook = new codification(data, new string[] {
"Attr1", "Attr2", ..., "AttrnumOfAttrColumns", "Result"});
Related
This question already has answers here:
All possible array initialization syntaxes
(19 answers)
Closed 2 years ago.
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-7788-99AA-BBCCDDEEFF00");
Now, My question is how i can assign values to an array list of Guid[]?
You can use the below code snippet to assign values to an array list of Guid[]
Guid[] arr = new Guid[4];
arr.SetValue(new Guid("11223344-5566-7788-99AA-BBCCDDEEFF00"), 0);
arr.SetValue(new Guid("26a285e5-5435-4daa-8d36-3186bd441cff"), 1);
arr.SetValue(new Guid("6d850084-d55a-45a9-9e83-5adf22cfbf04"), 2);
arr.SetValue(new Guid("ec43e526-51c0-41bc-b04a-2f2e72c894cc"), 3);
You can use the below code snippet to fill out your Guid array with randomly generated Guids.
Guid[] arr = new Guid[10];
for (int i = 0; i < 10; i++)
{
arr.SetValue(Guid.NewGuid(), i);
}
This question already has answers here:
Remove element of a regular array
(15 answers)
How to delete an element from an array in C#
(12 answers)
Removing an item from an array in C# [duplicate]
(7 answers)
How to remove an element from an array in C# [duplicate]
(3 answers)
Find and remove items from array in c#
(4 answers)
Closed 2 years ago.
I am making a basic word scrambling and guessing game. To make sure the same word doesn't appear again (example words used) I need to delete the selected word. I have looked all over for solutions however none have worked. Any help is appreciated!
//word bank
string[] wordBank = {
"iphone", "airpods", "laptop","computer","calculator","ram","graphics", "cable","internet","world wide web"
};
//select random word
Random wordRand = new Random();
int index = wordRand.Next(wordBank.Length);
string wordSelect = wordBank[index];
//delete word so can't be used again
List<string> wordBank = new List<string> {
"iphone", "airpods", "laptop","computer","calculator","ram","graphics", "cable","internet","world wide web"
};
//select random word
Random wordRand = new Random();
int index = wordRand.Next(wordBank.Count);
string wordSelect = wordBank[index];
wordBank.RemoveAt(index);
//or
wordBank.Remove(wordSelect);
This question already has answers here:
How to convert string to double with proper cultureinfo
(7 answers)
Closed 3 years ago.
I'm reading .txt file and spliting values into array like this:
for (int i = 0; i < articleItems.Length; i++)
{
List<string> splitStrings = articleItems[i].Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).ToList();
splitStrings[0] = splitStrings[0].Substring(12);
}
After that I'm trying to make object from those values, and everything is fine, but strange thing are happening here...
Here is the image from debugger, there is 14.80 at the beginning and when I convert that string to decimal it becomes 1480...:
Try
Double.Parse(splitStrings[2].ToString())
This question already has answers here:
How to populate/instantiate a C# array with a single value?
(26 answers)
Closed 6 years ago.
So lets say we have an array of doubles like this one that is later used for other stuff.
double[] myArray = new double[25];
How would I go about replacing all the values in that array with a set value?
There are flashier ways, but
for (int i = 0; i < myArray.Length; ++i){
myArray[i] = foo; /*the new value*/
}
is clear and simple.
The "flashy" way (simply create a new array):
var array = Enumerable.Repeat(value, count).ToArray();
Or
Array.ConvertAll(array, e => value);
This question already has answers here:
Array Size (Length) in C#
(9 answers)
Closed 6 years ago.
how should I convert Java loop code to C#?
Java:
for (int i = 0; i < edges[index].length; i++) {
edges[index][i] = 0;
edges[i][index] = 0;
}
I'm stuck with the edges[index].length part, is there any similar method in C#?
For reference, edges is int[,] array, index is some integer.
Try using GetLength?
edges.GetLength(index);
http://msdn.microsoft.com/en-us/library/system.array.getlength.aspx
In C#, Properties and Methods should start with an uppercased letter. Try Length instead of length