Create Array Parameters in C#
// November 14th, 2009 // Programming
Today i have request from ‘bad friend’ code name ‘mashudi’ to create Nearest Neighbor Class, Artificial Intelegent system that can compute distance from one to other node.
From this project I will share how to create a constructor or maybe you need for method that use array parameters.
Design of implementation in KNN node class will be like this :
KNNNode node1 = new KNNNode("Rose", 2.5, 4, 4.2);
KNNNode node2 = new KNNNode("Height", 2.5, 4, 4.2, 4.5, 6.3);
So you can add more parameters to that class.
Here my code in KNNNode class :
using System.Collections.Generic;
namespace Algorithm.KNN
{
public class KNNNode
{
List val;
string label;
public string Label
{
get { return label; }
set { label = value; }
}
// 'params float[] val' it will create array parameters
public KNNNode(string label, params float[] val)
{
//set label
this.label = label;
//Set actual size of val
this.val = new List(val.Length);
//iterate from first to last argument
//and fill to list
foreach (float v in val)
{
this.val.Add(v);
}
}
public int Count
{
get {
return val.Count;
}
}
//prevent default constructor inisialization
private KNNNode()
{ }
//Direct access to list value
public float this[int index]
{
get { return val[index]; }
set { val[index] = value; }
}
}
}
Hope it’s help
Willy Achmat Fauzi




hi,
First of all. Thanks very much for your useful post.
I just came across your blog and wanted to drop you a note telling you how impressed I was with the information you have posted here.
Please let me introduce you some info related to this post and I hope that it is useful for .Net community.
There is a good C# resource site, Have alook
http://www.csharptalk.com/2009/09/c-array.html
http://www.csharptalk.com/2009/10/creating-arrays.html
simi
thanks simi, hope it all useful for .Net community.
nice post palll
hope it’s usefull for me
This is a superb post wcode.net .
But I was wondering how do I suscribe to the RSS feed?
Hi, I’m very interested in Linux but Im a Super Newbie and I’m having trouble deciding on the right distribution for me (Havent you heard this a million times?) anyway here is my problem, I need a distribution that can switch between reading and writing in English and Japanese (Japanese Language Support) with out restarting the operating system.
Hello! aceacde interesting aceacde site!