i have 3 Array X,Y,Risk. i added a list generic (listtraining). if i click buttun Run my codes. But i dont want to use Session to transfer data. in winforms i dont need Session. May List collect data in his memory?
public partial class _Default : System.Web.UI.Page
{
double[] X;
double[] Y;
string[] Risk;
List<KNNAlgorithms.TrainigSet> listtraining;
protected void Page_Load(object sender, EventArgs e)
{
listtraining = new List<KNNAlgorithms.TrainigSet>();
if (!IsPostBack)
{
X = new double[] { 0.08, 0.07, 0.20, 1.00, 0.05, 0.20, 0.17, 0.15, 0.50, 0.10 };
Y = new double[] { 0.20, 0.07, 0.09, 0.20, 0.06, 0.25, 0.07, 0.55, 0.08, 0.06 };
Risk = new string[] { "erkek", "erkek", "erkek", "kadın", "erkek", "erkek", "erkek", "kadın", "erkek", "kadın" };
for (int i = 0; i < X.Length; i++)
{
KNNAlgorithms.TrainigSet tr = new KNNAlgorithms.TrainigSet();
tr.X = X[i];
tr.Y = Y[i];
tr.Risk = Risk[i];
listtraining.Add(tr);
}
Session.Add("listtraining", listtraining);
for (int i = 0; i < listtraining.Count; i++)
{
ListBox1.Items.Add(listtraining[i].X.ToString());
ListBox2.Items.Add(listtraining[i].Y.ToString());
ListBox3.Items.Add(listtraining[i].Risk.ToString());
}
}
}
protected void btnHesapla_Click(object sender, EventArgs e)
{
List<KNNAlgorithms.TrainigSet> listtraining = new List<KNNAlgorithms.TrainigSet>();
KNNAlgorithms.KNNModel knn = new KNNAlgorithms.KNNModel();
double x = double.Parse(txtX.Text);
double y = double.Parse(txtY.Text);
int k = int.Parse(txtKValue.Text);
listtraining = (List < KNNAlgorithms.TrainigSet > )Session["listtraining"];
lblResult.Text = "Üretilen Sonuç: " + knn.CalculatedDistancesArray(listtraining, x, y, "kadın", "erkek", k);
}
}
The list data needs to be persisted some where and your options on the web are session, viewstate, cache. The data stored in any of these mediums is actually stored in server’s memory.
The other option is that you serialize the data into XML or plain text [as it may suit you] and store it as a file on the server. This is generally not a good approach however coz you will end up with umpteen files on the file server.
One more option is to serialize the data, store it in a hidden input element on the form and pass it from page to page where you need it. This will be slightly cumbersome to code & handle overall.
The best bet i woudl still recommend as a session variable.