Which code segment should you use?

You are developing a shopping application by using Silverlight 4.
The application has a ListBox named lstBasket that contains the items in the shopping basket. You need to save the items in lstBasket to isolated storage. You also need to ensure that the items isolated storage are available to other Silverlight applications hosted on the same Web site.
Which code segment should you use?

You are developing a shopping application by using Silverlight 4.
The application has a ListBox named lstBasket that contains the items in the shopping basket. You need to save the items in lstBasket to isolated storage. You also need to ensure that the items isolated storage are available to other Silverlight applications hosted on the same Web site.
Which code segment should you use?

A.
var settings = IsolatedStorageSettings.ApplicationSettings;
var items = this.lstBasket.DataContext;
var token = “basket”;
if (settings.Contains(token))
settings[token] = items;
else
settings.Add(token, items);

B.
var store = IsolatedStorageFile.GetUserStoreForApplication();
var fileName = “basket.dat”;
var items = this.lstBasket.DataContext;
using (var fs = new IsolatedStorageFileStream(fileName, FileMode.Create,
FileAccess.Write, st ore))
{
var serializer = new DataContractSerializer(items.GetType());
serializer.WriteObject(fs, items);
}
store.CreateFile(fileName);

C.
var settings = IsolatedStorageSettings.SiteSettings;
var items = this.lstBasket.DataContext;
var token = “basket”;
if (settings.Contains(token))
settings[token] = items;
else
settings.Add(token, items);

D.
var store = IsolatedStorageFile. GetUserStoreForSite();
var fileName = “basket.dat”;
var items = this.lstBasket.DataContext;
using (var fs = new IsolatedStorageFileStream(fileName, FileMode.Create,
FileAccess.Write, st ore))
{
var serializer = new DataContractSerializer(items.GetType());
serializer.WriteObject(fs, items);
}
store.CreateFile(fileName);



Leave a Reply 0

Your email address will not be published. Required fields are marked *