2 Replies - 3516 Views - Last Post: 04 March 2012 - 08:21 AM

#1 Ricky65   User is offline

  • D.I.C Head

Reputation: 38
  • View blog
  • Posts: 115
  • Joined: 03-June 10

My problem with C#

Posted 04 March 2012 - 08:11 AM

Sorry, wrong forum.

This post has been edited by Ricky65: 04 March 2012 - 08:37 AM

Is This A Good Question/Topic? 0
  • +

Replies To: My problem with C#

#2 sepp2k   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2620
  • View blog
  • Posts: 4,175
  • Joined: 21-June 11

Re: My problem with C#

Posted 04 March 2012 - 08:18 AM

View PostRicky65, on 04 March 2012 - 04:11 PM, said:

Firstly, let me state that I like C#. I've created many applications using it and it's the best managed language I've used. However, I do have problems with it - most notably, the inability to return by reference.

This makes it impossible to write correct min/max functions in C#.

Consider the Math.Min function from Microsoft:
public static int Min(int val1, int val2)

This function will clearly do unnecessary coping. One does not need to know much about computer science to realise that to pick the smaller of the two integers, no copying is needed.

Passing the integers by reference would actually be less efficient than passing them by value because of the added indirection.


We're passing integers here but if we were passing arbitrarily large objects the overhead of three unneeded copies could be quite dramatic.

You realize that arbitrarily large object usually have a reference type and won't actually be copied, right?


// Use a string array to loop over.
	string[] ferns =
	// Loop with the foreach keyword.
	foreach (string value in ferns)

On every iteration the string is being copied.

No, it's not. Strings are reference types.
Was This Post Helpful? 0
  • +
  • -

#3 RexGrammer   User is offline

  • Coding Dynamo
  • member icon

Reputation: 183
  • View blog
  • Posts: 785
  • Joined: 27-October 11

Re: My problem with C#

Posted 04 March 2012 - 08:21 AM

And you're calling us to discuss on this subject?

This is something more that is suitable as a suggestion to the .NET development team. Nice observations by the way, never thought about it since I mostly deal with computers where it's less necessary to optimize than for Windows Phone. Optimization really comes naturally to me, the most logical way of doing things is most likely the most optimized one also. :D

This post has been edited by RexGrammer: 04 March 2012 - 08:22 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1