What is the difference between myArray.GetValue(2) and myArray[2] in C#? -


is there difference between using myarray.getvalue(2) , myarray[2]?

for example:

namespace consoleapplication16 {     class program     {         static void main(string[] args)         {             int[] numbers = new int[] { 1, 2, 3, 4 };             console.writeline(numbers.getvalue(3));             console.writeline(numbers[3]);             console.readline();         }     } } 

getvalue return type object while using index return type specific array.

you can see in fiddle (code below) variable val1 can have string stored in it, val2 can used integer.

public static void main() {     int[] numbers = new int[]{1, 2, 3, 4};     var val1 = numbers.getvalue(3);     var type = val1.gettype();     var val2 = numbers[3];      console.writeline(type.tostring());     val1 = "hello";     type = val1.gettype();     console.writeline(type.tostring()); } 

this result in boxing , unboxing, won't have effect on small code snippet, if used in large scale potentially affect performance.


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -