回答編集履歴
3
ついき2
answer
CHANGED
@@ -49,4 +49,52 @@
|
|
49
49
|
}
|
50
50
|
}
|
51
51
|
}
|
52
|
+
```
|
53
|
+
|
54
|
+
**【追記2】**
|
55
|
+
|
56
|
+
2018/05/14 15:21 のコメントで、
|
57
|
+
|
58
|
+
> ID が各ユーザーに固有のもの(DB で言うと主キーのようなもの)であれば、Person に含め、Linq などを使って取得する方がすっきりしてますし、今時のやり方として自分的にはお勧めです。後でサンプルを回答欄に追記しておきます。
|
59
|
+
|
60
|
+
・・・と書きましたがそれを以下に書きます。
|
61
|
+
|
62
|
+
```
|
63
|
+
using System;
|
64
|
+
using System.Collections.Generic;
|
65
|
+
using System.Linq;
|
66
|
+
using System.Text;
|
67
|
+
using System.Data;
|
68
|
+
using System.Xml;
|
69
|
+
|
70
|
+
namespace ConsoleApplication4
|
71
|
+
{
|
72
|
+
public class Person2
|
73
|
+
{
|
74
|
+
public int ID { get; set; }
|
75
|
+
public string Name { get; set; }
|
76
|
+
public int Age { get; set; }
|
77
|
+
}
|
78
|
+
|
79
|
+
class Program
|
80
|
+
{
|
81
|
+
static void Main(string[] args)
|
82
|
+
{
|
83
|
+
List<Person2> data2 = new List<Person2>() {
|
84
|
+
new Person2() { ID = 1000, Name = "山田太郎", Age = 27 },
|
85
|
+
new Person2() { ID = 1001, Name = "佐藤次郎", Age = 30 }
|
86
|
+
};
|
87
|
+
|
88
|
+
var person = (from p in data2
|
89
|
+
where p.ID == 1000
|
90
|
+
select p).FirstOrDefault();
|
91
|
+
|
92
|
+
Console.WriteLine("ID = {0}, Name = {1}, Age = {2}",
|
93
|
+
person.ID, person.Name, person.Age);
|
94
|
+
|
95
|
+
// 結果は:
|
96
|
+
// ID = 1000, Name = 山田太郎, Age = 27
|
97
|
+
}
|
98
|
+
}
|
99
|
+
}
|
52
100
|
```
|
2
追記
answer
CHANGED
@@ -7,4 +7,46 @@
|
|
7
7
|
ASP.NET Web アプリでどのようにリソースを使って多言語するかの例を書いた記事をご参考に紹介します。
|
8
8
|
|
9
9
|
aspx ページでのリソースの利用
|
10
|
-
[http://surferonwww.info/BlogEngine/post/2015/04/21/use-of-resources-in-aspx-page.aspx](http://surferonwww.info/BlogEngine/post/2015/04/21/use-of-resources-in-aspx-page.aspx)
|
10
|
+
[http://surferonwww.info/BlogEngine/post/2015/04/21/use-of-resources-in-aspx-page.aspx](http://surferonwww.info/BlogEngine/post/2015/04/21/use-of-resources-in-aspx-page.aspx)
|
11
|
+
|
12
|
+
**【追記】**
|
13
|
+
|
14
|
+
2018/05/14 12:46 のコメントで「回答欄に案を書いておきます」と書きましたがそれを以下に書きます。あくまで「案」で、実際の目的によってはもっと適切な方法があるかもしれません。
|
15
|
+
|
16
|
+
```
|
17
|
+
using System;
|
18
|
+
using System.Collections.Generic;
|
19
|
+
using System.Linq;
|
20
|
+
using System.Text;
|
21
|
+
using System.Data;
|
22
|
+
using System.Xml;
|
23
|
+
|
24
|
+
namespace ConsoleApplication4
|
25
|
+
{
|
26
|
+
public class Person
|
27
|
+
{
|
28
|
+
public string Name { get; set; }
|
29
|
+
public int Age { get; set; }
|
30
|
+
}
|
31
|
+
|
32
|
+
class Program
|
33
|
+
{
|
34
|
+
static void Main(string[] args)
|
35
|
+
{
|
36
|
+
Dictionary<int, Person> data = new Dictionary<int, Person>();
|
37
|
+
data.Add(1000, new Person() { Name = "山田太郎", Age = 27 });
|
38
|
+
data.Add(1001, new Person() { Name = "佐藤次郎", Age = 30 });
|
39
|
+
|
40
|
+
foreach (KeyValuePair<int, Person> kvp in data)
|
41
|
+
{
|
42
|
+
Console.WriteLine("Key = {0}, Name = {1}, Age = {2}",
|
43
|
+
kvp.Key, kvp.Value.Name, kvp.Value.Age);
|
44
|
+
}
|
45
|
+
|
46
|
+
// 結果は:
|
47
|
+
// Key = 1000, Name = 山田太郎, Age = 27
|
48
|
+
// Key = 1001, Name = 佐藤次郎, Age = 30
|
49
|
+
}
|
50
|
+
}
|
51
|
+
}
|
52
|
+
```
|
1
追伸
answer
CHANGED
@@ -1,1 +1,10 @@
|
|
1
|
-
「絶対ない」というのは意味不明ですが、質問者さんが例に挙げた多言語化の話なら、リソースをつかうので質問者さんが書いたソースのようなことは普通はしません。
|
1
|
+
「絶対ない」というのは意味不明ですが、質問者さんが例に挙げた多言語化の話なら、リソースをつかうので質問者さんが書いたソースのようなことは普通はしません。
|
2
|
+
|
3
|
+
**【追伸】**
|
4
|
+
|
5
|
+
PHP とのことですから Web アプリの話、C# に移行ということは ASP.NET の話と想像していますが(想像が違っていたら以下はスルーしてください)・・・
|
6
|
+
|
7
|
+
ASP.NET Web アプリでどのようにリソースを使って多言語するかの例を書いた記事をご参考に紹介します。
|
8
|
+
|
9
|
+
aspx ページでのリソースの利用
|
10
|
+
[http://surferonwww.info/BlogEngine/post/2015/04/21/use-of-resources-in-aspx-page.aspx](http://surferonwww.info/BlogEngine/post/2015/04/21/use-of-resources-in-aspx-page.aspx)
|