當(dāng)前位置:首頁(yè) > IT技術(shù) > 編程語(yǔ)言 > 正文

C#與Java的長(zhǎng)度計(jì)算API的區(qū)別
2021-10-22 09:58:59

C#:

 1 public class demo01
 2     {
 3         public void test01()
 4         {
 5             //數(shù)組的長(zhǎng)度是.Length
 6             int[] ary = new int[] { 1, 2, 3 };
 7             Console.WriteLine(ary.Length);
 8 
 9             //字符串的長(zhǎng)度是.Length
10             string str = "abc";
11             Console.WriteLine(str.Length);
12 
13             //List的長(zhǎng)度是.Count
14             List<int> list = new List<int>();
15             Console.WriteLine(list.Count);
16 
17             //Set的長(zhǎng)度是.Count
18             HashSet<string> set = new HashSet<string>();
19             Console.WriteLine(set.Count);
20 
21             //Dictionary的長(zhǎng)度是.Count
22             Dictionary<string, int> dic = new Dictionary<string, int>();
23             Console.WriteLine(dic.Count);
24         }
25     }

?

Java:

 1 public class demo01 {
 2     public static void main(String[] args) {
 3         //數(shù)組的長(zhǎng)度是.length
 4         int[] ary = new int[] {1,2,3};        
 5         System.out.println(ary.length);
 6         
 7         //字符串的長(zhǎng)度是.length()
 8         String str = "abc";
 9         System.out.println(str.length());
10         
11         //List的長(zhǎng)度是.size()
12         List<Integer> list = new ArrayList<Integer>();
13         System.out.println(list.size());
14         
15         //Set的長(zhǎng)度是.size()
16         Set<String> set = new HashSet<>();
17         System.out.println(set.size());
18         
19         //Map的長(zhǎng)度是.size()
20         Map<String, Integer> map = new HashMap<String, Integer>();
21         System.out.println(map.size());
22     }
23 }

?

本文摘自 :https://www.cnblogs.com/

開(kāi)通會(huì)員,享受整站包年服務(wù)立即開(kāi)通 >