doubt regarding the use of arrayshttp://forums.asp.net/t/1766841.aspx/1?doubt+regarding+the+use+of+arraysTue, 07 Feb 2012 14:45:13 -050017668414820544http://forums.asp.net/p/1766841/4820544.aspx/1?doubt+regarding+the+use+of+arraysdoubt regarding the use of arrays <p>First of all I would like to thank the forum unlimited times for writing to my difficulties every time I post---- is there any way to thank the members other than this?</p> <p>Now my DIFFICULTY here</p> <p>&nbsp;</p> <p>there is a doubt regarding the use of arrays;</p> <p>step1 )&nbsp; We may define an array as:-<br> int[] arra ;</p> <p>&nbsp;</p> <p>step2 )&nbsp; We would initialize it as:-<br> arra= new int[4] // say</p> <p>&nbsp;</p> <p>step3i )&nbsp; or in a single step as:-<br> int[] arra = new int[4];</p> <p><br> or</p> <p>step3ii )&nbsp;&nbsp; <br> int[] arra = new int[4]{45,5,78,2};</p> <p><br> Now there is a piece of code .<br> &nbsp;&nbsp;&nbsp;&nbsp; //Here&nbsp; we would the Reverse() method of the array type in string<br> &nbsp;</p> <p><br> static class Helpers<br> {<br> public static string Reverse(string s)<br> {<br> char[] characters = s.ToCharArray();</p> <p>&nbsp;&nbsp;&nbsp; //&nbsp; what this ABOVE step does in relation to the steps written above?<br> &nbsp;&nbsp;&nbsp; // Does it create a STACK or a MANAGED HEAP?</p> <p>Array.Reverse(characters);</p> <p>&nbsp;&nbsp;&nbsp; // are we initializing the array in the step BELOW</p> <p>return new string(characters);<br> }<br> }</p> <p>&nbsp;</p> <p>&nbsp;</p> <p>please help</p> <p>&nbsp;</p> 2012-02-07T12:25:40-05:004820802http://forums.asp.net/p/1766841/4820802.aspx/1?Re+doubt+regarding+the+use+of+arraysRe: doubt regarding the use of arrays <p>@ <a title="amigo 1" href="http://forums.asp.net/members/amigo%201.aspx">amigo 1</a></p> <p>what makes you ask your question?; specifically have you executed your code?</p> <p>Two things you can do to find out what your code does ...</p> <p>(a) run it in LINQPad 4*</p> <p>(b) create a console application in vs2010 and DEBUG your code.</p> <p>For small pieces of code like your example in this thread's O.P., i use LINQPad 4 probably 99% of the time.</p> <p>Please do (a) and/or (b) and let us know what you've learned.</p> <p>BTW, (b) is also important because it's absolutely essential to know how to use the vs2010 debugger.</p> <p>g.</p> <p>*&nbsp;&nbsp; if you do not have LINQPad 4:</p> <p>TOOLS ... get yourself a FREE copy of LINQPad 4 (<a href="http://linqpad.net/">http://linqpad.net</a>) .. Joe Albahari's LINQPad 4 is an awesome programmer's scratch pad that enables you to quickly check out code snippets you find in books and on web sites plus LINQPad also lets you rapidly experiment with c# ideas before committing them to vs2010.</p> <p>LINQPad 4 supports c#, F#, SQL, vb.</p> 2012-02-07T14:17:43-05:004820855http://forums.asp.net/p/1766841/4820855.aspx/1?Re+doubt+regarding+the+use+of+arraysRe: doubt regarding the use of arrays <p>static class Helpers<br> {<br> public static string Reverse(string s)<br> {<br> char[] characters = s.ToCharArray();</p> <p>&nbsp;&nbsp;&nbsp; //&nbsp; what this ABOVE step does in relation to the steps written above?</p> <p>&nbsp;&nbsp;&nbsp; <strong>//this&nbsp;will&nbsp;also initialise the array variable. while in the above cases&nbsp;declarative values were assigned in array... here, the result of s.ToCharArrays will be used.</strong><br> &nbsp;&nbsp;&nbsp; // Does it create a STACK or a MANAGED HEAP?</p> <p>&nbsp;&nbsp; <strong>//since, the array is getting initizlised, the references array values would be stored in heap</strong></p> <p>Array.Reverse(characters);</p> <p>&nbsp;&nbsp;&nbsp; // are we initializing the array in the step BELOW</p> <p>&nbsp;&nbsp; <strong>//no this will initialise string variable (which is again reference type)</strong></p> <p>return new string(characters);<br> }<br> }</p> <p>hope this helps...</p> 2012-02-07T14:45:13-05:00