1

1) It is better to return an array as an argument or with the "return" ?

2) At jagged array the

`GetLength(0)` is the same with Length ?

3) Whats the difference between string.copy() and Clone() ?

4) Is string.Concat(string1, string2) the same with string1 + string2 ?

5) Whats the difference between SetValue and anArray[0] = ... ?

5
  • I don't know who voted to close as "TooBroad". If this question is broad then he might not be knowing basics of c# or .net Commented Nov 10, 2013 at 20:47
  • @SriramSakthivel I guess some folk deem five questions in one as too broad? It's an odd vote though. Commented Nov 10, 2013 at 20:52
  • @DavidArno May be. instructing Op to ask questions seperately would be fine though. Commented Nov 10, 2013 at 20:56
  • 1
    Welcome to stackoverflow. Please ask one question at a time, If questions are related more than one is fine. I can't find any relation between string.Concat and Array.Setvalue. So that peoples searching for same thing would get benefited. also write good and appropriate titles. Thank you. Commented Nov 10, 2013 at 20:59
  • I think most of such answers you can just find by using Google. Commented Nov 10, 2013 at 21:29

2 Answers 2

5
  1. It doesn't matter to the array. As a best practice, try to use return statements rather than returning through an argument list. The only reason to ever use the argument list is if you have more than one output, and generally you want to design smaller methods that do one thing.

  2. Yes

  3. The Clone() method is for the ICloneable interface, which unfortunately is not adequately defined as a deep vs shallow copy, and so is best avoided.

  4. The results of String.Concat() vs string1 + string2 are the same, the means of achieving those results are different, sometimes with noticeable performance implications.

  5. IIRC, the indexer property of the array (the [] brackets) just calls the SetValue() method. So nothing, really.

Sign up to request clarification or add additional context in comments.

1 Comment

About the first question in the book i read it says " To return an array through the return type of the method, another array must be declared and space allocated locally for it in the method.This additional space for the size of the array is unnecessary if the array is sent as an argument because arrays are always passed by reference. Sending the array as an argument passes the address of the one declared in the calling method and eliminates the need to declare a local array." So what it's said is false ?
0

About the first question in the book i read it says " To return an array through the return type of the method, another array must be declared and space allocated locally for it in the method.This additional space for the size of the array is unnecessary if the array is sent as an argument because arrays are always passed by reference. Sending the array as an argument passes the address of the one declared in the calling method and eliminates the need to declare a local array." So what it's said is false ?

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.