 |
|
สอบถามเรื่องการใช้งานและการประยุกต์ไปใช้งานของ Dictionary (Collection) |
|
 |
|
|
 |
 |
|
ลักษณะคล้ายๆ กัน
ต่างกันที่มันมี key กับ value แต่ array มันมี value อย่างเดียว
ส่วนการใช้งาน เราเอาไว้วนลูปแบบต้องการใช้งาน key ด้วย
|
 |
 |
 |
 |
Date :
2016-04-08 09:00:57 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
http://www.dotnetperls.com/collections
ได้ความแตกต่างประมาณนี้ครับ
Code (C#)
using System;
using System.Collections.Generic;
class Program
{
static void Main()
{
Dictionary<string, int> dictionary =
new Dictionary<string, int>();
dictionary.Add("cat", 2);
dictionary.Add("dog", 1);
dictionary.Add("llama", 0);
dictionary.Add("iguana", -1);
}
}
Code (C#)
using System.Collections.Generic;
class Program
{
static void Main()
{
List<int> list = new List<int>();
list.Add(2);
list.Add(3);
list.Add(5);
list.Add(7);
}
}
Code (C#)
class Program
{
static void Main()
{
// String arrays with 3 elements:
string[] arr1 = new string[] { "one", "two", "three" };
string[] arr2 = { "one", "two", "three" };
var arr3 = new string[] { "one", "two", "three" };
string[] arr4 = new string[3];
arr4[0] = "one";
arr4[1] = "two";
arr4[2] = "three";
}
}
Code (C#)
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main()
{
IEnumerable<int> result = from value in Enumerable.Range(0, 2)
select value;
// Loop.
foreach (int value in result)
{
Console.WriteLine(value);
}
// We can use extension methods on IEnumerable<int>
double average = result.Average();
// Extension methods can convert IEnumerable<int>
List<int> list = result.ToList();
int[] array = result.ToArray();
}
}
|
 |
 |
 |
 |
Date :
2016-04-08 09:02:07 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อืมๆ ลักษณะคือ class ใน list สินะ
|
 |
 |
 |
 |
Date :
2016-04-08 10:14:25 |
By :
deksoke |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ส่วนตัวถ้าให้ใช้ Dictionary
ผมสร้าง list class มาง่ายกว่าครับ
เพราะ เก็บ method ค่าต่างๆได้ด้วย
Code (C#)
public class _UncerMulti
{
public double KeysValue; public double UncerValue;
public double Multi()
{
return UncerValue / KeysValue;
}
public double MultiPow()
{
return System.Math.Pow(UncerValue / KeysValue,2);
}
public double MultiSqrt()
{
return System.Math.Sqrt(UncerValue / KeysValue);
}
}
|
 |
 |
 |
 |
Date :
2016-04-08 10:29:11 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|