Length









How do I use Length
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: frmCapNhat.cs Copy
54         private void listView1_SelectedIndexChanged(object sender, EventArgs e)
55         {
56             bool bdapan = false;
57             for (int i = 0; i < listView1.Items.Count; i++)
58             {
59                 if (listView1.Items[i].Selected)
60                 {
61                     textBox5.Text = listView1.Items[i].SubItems[0].Text;
62                     textBox1.Text = listView1.Items[i].SubItems[2].Text;
63                     textBox2.Text = listView1.Items[i].SubItems[3].Text;
64                     textBox3.Text = listView1.Items[i].SubItems[4].Text;
65                     textBox4.Text = listView1.Items[i].SubItems[5].Text;
66                     richTextBox1.Text = listView1.Items[i].SubItems[1].Text;
67                     string t = listView1.Items[i].SubItems[6].Text.ToString().Trim();
68                     if (t.Length >= 2)
69                     {
70                         for (int ii = 0; ii < t.Length; ii++)
71                         {
72                             t2 = t[0].ToString();
73                             if (t[1].ToString() == "")
74                             {
75                                 t1 = "NULL";
76                             }
77                             else
78                             {
79                                 t1 = t[1].ToString();
80                             }
81                         }
82                     }
83                     else
84                     {
85                         t2 = t;
86                         t1 = "NULL";
87                     }
88                     Macdinh();
89                     if (t1 == "A")
90                     {
91                         checkBox1.Checked = true;
92                     }
93                     if (t1 == "B")
94                     {
95                         checkBox2.Checked = true;
96                     }
97                     if (t1 == "C")
98                     {
99                         checkBox3.Checked = true;
100                     }
101                     if (t1 == "D")
102                     {
103                         checkBox4.Checked = true;
104                     }
105
106                     if (t2 == "A")
107                     {
108                         checkBox1.Checked = true;
109                     }
110                     if (t2 == "B")
111                     {
112                         checkBox2.Checked = true;
113                     }
114                     if (t2 == "C")
115                     {
116                         checkBox3.Checked = true;
117                     }
118                     if (t2 == "D")
119                     {
120                         checkBox4.Checked = true;
121                     }
122                     bdapan = true;
123                 }
124                 if (bdapan == false)
125                 {
126                     Bandau();
127                 }
128             }
129
130         }
File name: frmCapNhat.cs Copy
259         private string SDienMaTuDong(string sMa, SqlCommand sqlcmd, SqlConnection sqlcon)
260         {
261             int iMax = 1;
262             sqlcmd = new SqlCommand("select mach from cauhoi", sqlcon);
263             SqlDataReader sqlreader = sqlcmd.ExecuteReader();
264             while (sqlreader.Read())
265             {
266                 for (int i = 0; i < sqlreader.GetValue(0).ToString().Length; i++)
267                 {
268                     int iSoSanh = int.Parse(sqlreader.GetValue(0).ToString().Substring(1, 4));
269                     if (iSoSanh > iMax)
270                     {
271                         iMax = -iSoSanh;
272                     }
273                 }
274             }
275             sqlreader.Close();
276             if (iMax + 1 < 10)
277             {
278                 sMa = string.Concat("C", "000", iMax + 1);
279             }
280             if (iMax + 1 >= 10)
281             {
282                 sMa = string.Concat("C", "00", iMax + 1);
283             }
284             if (iMax + 1 >= 100)
285             {
286                 sMa = string.Concat("C", "0", iMax + 1);
287             }
288             if (iMax + 1 >= 1000)
289             {
290                 sMa = string.Concat("C", iMax + 1);
291             }
292             return sMa;
293         }
File name: frmLuaChon.cs Copy
36         private void timer1_Tick(object sender, EventArgs e)
37         {
38             lbluachon.Text = lbluachon.Text.Substring(lbluachon.Text.Length - 1, 1) + lbluachon.Text.Substring(0, lbluachon.Text.Length - 1);
39         }
File name: frmMain.cs Copy
19         private void frmMain_Load(object sender, EventArgs e)
20         {
21             tship.Text = "Ngày "+DateTime.Now.Day.ToString() + " Tháng " + DateTime.Now.Month.ToString() + " Năm " + DateTime.Now.Year.ToString();
22             tship2.Text = tship2.Text.Substring(tship2.Text.Length - 1, 1) + tship2.Text.Substring(0, tship2.Text.Length - 1);
23
24             //frmLogin fLog = new frmLogin();
25             //fLog.MdiParent = this;
26             //fLog.Show();
27             //this.WindowState = FormWindowState.Normal;
28         }
File name: DemoOwnershipGui.cs Copy
23     public void OnGUI()
24     {
25         GUI.skin = this.Skin;
26         GUILayout.BeginArea(new Rect(Screen.width - 200, 0, 200, Screen.height));
27         {
28             string label = TransferOwnershipOnRequest ? "passing objects" : "rejecting to pass";
29             if (GUILayout.Button(label))
30             {
31                 this.TransferOwnershipOnRequest = !this.TransferOwnershipOnRequest;
32             }
33         }
34         GUILayout.EndArea();
35
36
37
38         if (PhotonNetwork.inRoom)
39         {
40             int playerNr = PhotonNetwork.player.ID;
41             string playerIsMaster = PhotonNetwork.player.isMasterClient ? "(master) " : "";
42             string playerColor = PlayerVariables.GetColorName(PhotonNetwork.player.ID);
43             GUILayout.Label(string.Format("player {0}, {1} {2}(you)", playerNr, playerColor, playerIsMaster));
44
45             foreach (PhotonPlayer otherPlayer in PhotonNetwork.otherPlayers)
46             {
47                 playerNr = otherPlayer.ID;
48                 playerIsMaster = otherPlayer.isMasterClient ? "(master)" : "";
49                 playerColor = PlayerVariables.GetColorName(otherPlayer.ID);
50                 GUILayout.Label(string.Format("player {0}, {1} {2}", playerNr, playerColor, playerIsMaster));
51             }
52
53             if (PhotonNetwork.inRoom && PhotonNetwork.otherPlayers.Length == 0)
54             {
55                 GUILayout.Label("Join more clients to switch object-control.");
56             }
57         }
58         else
59         {
60             GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());
61         }
62     }
File name: ChatGui.cs Copy
296     public void OnConnected()
297     {
298         if (this.ChannelsToJoinOnConnect != null && this.ChannelsToJoinOnConnect.Length > 0)
299         {
300             this.chatClient.Subscribe(this.ChannelsToJoinOnConnect, this.HistoryLengthToFetch);
301         }
302
303         this.chatClient.AddFriends(new string[] {"tobi", "ilya"}); // Add some users to the server-list to get their status updates
304         this.chatClient.SetOnlineStatus(ChatUserStatus.Online); // You can set your online state (without a mesage).
305     }
File name: GUIFriendFinding.cs Copy
28     public static string[] FetchFriendsFromCommunity()
29     {
30         string[] friendsList = new string[9];
31         int u = 0;
32         for (int i = 0; i < friendsList.Length; i++)
33         {
34             string usrName = "usr" + u++;
35             if (usrName.Equals(PhotonNetwork.playerName))
36             {
37                 usrName = "usr" + u++; // skip friend if the name is yours
38             }
39             friendsList[i] = usrName;
40         }
41
42         return friendsList;
43     }
File name: GUIFriendsInRoom.cs Copy
15     public void OnGUI()
16     {
17         if (PhotonNetwork.connectionStateDetailed != PeerState.Joined)
18         {
19             return;
20         }
21
22         GUILayout.BeginArea(GuiRect);
23
24         GUILayout.Label("In-Game");
25         GUILayout.Label("For simplicity, this demo just shows the players in this room. The list will expand when more join.");
26         GUILayout.Label("Your (random) name: " + PhotonNetwork.playerName);
27         GUILayout.Label(PhotonNetwork.playerList.Length + " players in this room.");
28         GUILayout.Label("The others are:");
29         foreach (PhotonPlayer player in PhotonNetwork.otherPlayers)
30         {
31             GUILayout.Label(player.ToString());
32         }
33
34         if (GUILayout.Button("Leave"))
35         {
36             PhotonNetwork.LeaveRoom();
37         }
38         GUILayout.EndArea();
39     }
File name: PunStartup.cs Copy
34     static void OnUpdate()
35     {
36         bool doneBefore = EditorPrefs.GetBool("PunDemosOpenedBefore");
37         if (doneBefore)
38         {
39             EditorApplication.update -= OnUpdate;
40             return;
41         }
42
43         if (String.IsNullOrEmpty(EditorApplication.currentScene) && EditorBuildSettings.scenes.Length == 0)
44         {
45             #if UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_5 || UNITY_5_1 || UNITY_5_2
46             if (EditorApplication.isUpdating) return;
47             #endif
48
49             LoadPunDemoHub();
50             SetPunDemoBuildSettings();
51             EditorPrefs.SetBool("PunDemosOpenedBefore", true);
52             Debug.Log("No scene was open. Loaded PUN Demo Hub Scene and added demos to build settings. Ready to go! This auto-setup is now disabled in this Editor.");
53         }
54     }
File name: PunStartup.cs Copy
80     public static void SetPunDemoBuildSettings()
81     {
82         // find path of pun guide
83         string[] tempPaths = Directory.GetDirectories(Application.dataPath + "/Photon Unity Networking", "Demos", SearchOption.AllDirectories);
84         if (tempPaths == null || tempPaths.Length != 1)
85         {
86             return;
87         }
88
89         // find scenes of guide
90         string guidePath = tempPaths[0];
91         tempPaths = Directory.GetFiles(guidePath, "*.unity", SearchOption.AllDirectories);
92
93         if (tempPaths == null || tempPaths.Length == 0)
94         {
95             return;
96         }
97
98         // add found guide scenes to build settings
99         List sceneAr = new List();
100         for (int i = 0; i < tempPaths.Length; i++)
101         {
102             //Debug.Log(tempPaths[i]);
103             string path = tempPaths[i].Substring(Application.dataPath.Length - "Assets".Length);
104             path = path.Replace('\\', '/');
105             //Debug.Log(path);
106
107             if (path.Contains("PUNGuide_M2H"))
108             {
109                 continue;
110             }
111
112             if (path.Contains("Hub"))
113             {
114                 sceneAr.Insert(0, new EditorBuildSettingsScene(path, true));
115                 continue;
116             }
117
118             sceneAr.Add(new EditorBuildSettingsScene(path, true));
119         }
120
121         EditorBuildSettings.scenes = sceneAr.ToArray();
122         EditorApplication.OpenScene(sceneAr[0].path);
123     }

Length 135 lượt xem

Gõ tìm kiếm nhanh...