c# - Passing Object vs String as Method Paramter -
with following code, understand getstringagain(classone.str1) better getastring(classone) because want pass in necessary because of data hiding/encapsulation etc.
however, there memory benefits? classone object larger string, since in both methods, passing in reference object, , therefore reference copied stack, both efficient in terms of memory?
class classone() { public string str1 = "string1"; public string str2 = "string2"; } class classtwo() { public classtwo() { classone classone = new classone(); string = getastring(classone); string b = getstringagain(classone.str1) } private string getastring(classone classone) { return classone.str1; } private string getstringagain(string str) { return str; } }
string , class reference types
it means 2 functions take reference managed heap actual data held
nothing copied.
if know pointers basicly same passing pointer.
Comments
Post a Comment