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

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

C#:

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

?

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

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