0

Since Dictionary objects are Reference type themselves
Is it meaningless to pass Dictionary to method by ref !
this method MUST edit the dictionary items and add new items as well
Those dictionary objects are Global and they are used in all of my app classes and forms
Does Dictionary objects are passed to the methods by ref by default?
As example consider this method defintion:

internal static void GetUserData(ref Dictionary<string,int> UserNameIdDictionary) {...}

I use this dictionary to store User Name/ID data which will be retrieved from SQL Server Database this Dictionary will allow the use of these data from The whole application
Side Note/Question Does it wrong approach storing the retrieved data inside dictionary objects [from performance perspective] ?

  • 3
    Here's a decent explanation of "why" you'd want to do this: http://stackoverflow.com/questions/186891/why-use-ref-keyword-when-passing-an-object So, short answer is no, it isn't meaningless, depending on what you're doing. – Broots Waymb Jul 17 '15 at 14:33
  • 1
    This means only if you reallocate the dictionary in your procedure, e.g. UserNameIdDictionary = new Dictionary() – Graffito Jul 17 '15 at 14:33
  • @DangerZone Thank you, this is was detailed answer for my question – user3779823 Jul 17 '15 at 14:34
  • 4
    Passing a parameter by reference is not the same thing as passing a reference type parameter – vc 74 Jul 17 '15 at 14:36
  • 1
    Despite the similar naming, reference types (and the variables which hold references to them) and "pass by reference" (`ref`) are actually two different concepts. – Damien_The_Unbeliever Jul 17 '15 at 14:36
  • @vc74 ,Damien_The_Unbeliever Thanks for mentioning that reference types and passing by reference are not the same thing It seems like I Still Have a long way to go – user3779823 Jul 17 '15 at 14:40

0 Answers0