Scat object ref
-
hi everybody I have a method by following signature and body:
private void LoadByItem(Item item) { MyDBDataContext my = new MyDBDataContext(); var query = from q in my.Items where q.Id == item.Id select q; item = query.First<Item>>; }
when I send the argument to the above method, after method process I get nothing in item while in the method item had value. I think after assigning item to query it work as a value type not a reference type. please let me know how can I get the reference of item without using ref in function signature. -
hi everybody I have a method by following signature and body:
private void LoadByItem(Item item) { MyDBDataContext my = new MyDBDataContext(); var query = from q in my.Items where q.Id == item.Id select q; item = query.First<Item>>; }
when I send the argument to the above method, after method process I get nothing in item while in the method item had value. I think after assigning item to query it work as a value type not a reference type. please let me know how can I get the reference of item without using ref in function signature.Sorry, that won't work unless you use ref. Do this instead:
Item loadedItem = LoadByItem(item.Id);
...
private Item LoadByItem(int id) // if Id is not an int, change this accordingly
{
var matches = from item in new MyDBDataContext().Items
where item.Id == id
select item;return matches.First();
}Tech, life, family, faith: Give me a visit. I'm currently blogging about: I'm Offended That You're Offended! The apostle Paul, modernly speaking: Epistles of Paul Judah Himango