object - C# - Returning mixed types in a function -
i have different data types need in function. data needs processed in function , returned object believe called.
this not tested code wrote here, think displays im trying .. hope guys can me out how it.
private void button_click(object sender, routedeventargs e) { // here im calling function returns data object object thoseprocesseddata = sometestobject(5, "abc", someotherthing); // when returned want able use different data so. string useitlikethis = thoseprocesseddata.newstring; int numberslikethis = thoseprocesseddata.newnumber; } public object sometestobject(int numbers, string letters, anothertype anothertype) { string newstring = letters.substring(0,5); int newnumber = numbers + 10; anothertype newtype = anothertype.something(); return processeddata; }
please guys dont kill me, if stupid question. im still new c# ..
if dont im trying do, please ask! since english not best thought way best show want..
create class holds data want pass , return:
public class data { public string letters { get; set; } public int number { get; set; } public anothertype thing { get; set; } }
pass method:
var data = new data { letters = "abc", number = 5, thing = someotherthing }; dosomething(data); // here data have modified values
thus class reference type, changes members inside dosomething method, reflected in data
object reference. so, changes can like:
public void dosomething(data data) { data.letters = data.letters.substring(0,5); data.number += 10; data.thing.something(); }
Comments
Post a Comment