You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// What the heck is data for?
var data = new { Name = "John", Age = 42 };
var stream1 = new MemoryStream();
var ser1 = new DataContractJsonSerializer(typeof(object));
ser1.WriteObject(stream1, data);
stream1.Position = 0;
var sr1 = new StreamReader(stream1);
Console.Write("JSON form of Data object: ");
Console.WriteLine(sr1.ReadToEnd());
Good:
var person = new Person
{
Name = "John",
Age = 42
};
var stream2 = new MemoryStream();
var ser2 = new DataContractJsonSerializer(typeof(Person));
ser2.WriteObject(stream2, data);
stream2.Position = 0;
var sr2 = new StreamReader(stream2);
Console.Write("JSON form of Data object: ");
Console.WriteLine(sr2.ReadToEnd());
As you can see in ser2.WriteObject(stream2, data); should be person not data as data has not been declared and to match what bad code block is doing
The text was updated successfully, but these errors were encountered:
IsaacMorris1980
changed the title
Searchable Names Part1 in Good code section data is used instead of person
Searchable Names Part1 in Good code section incorrect variable is used
Jul 7, 2023
@olmeyer I agree i was not asking about all the incorrect items on the good side
ar person = new Person
{
Name = "John",
Age = 42
};
var stream2 = new MemoryStream();
var ser2 = new DataContractJsonSerializer(typeof(Person));
ser2.WriteObject(stream2, data); // i was asking about here should it not say person instead of data
In Searchable Names Part 1 seaction 2
Bad:
Good:
As you can see in ser2.WriteObject(stream2, data); should be person not data as data has not been declared and to match what bad code block is doing
The text was updated successfully, but these errors were encountered: