patterncsharpMinor
Getting contact information
Viewed 0 times
contactgettinginformation
Problem
How can I improve this code?
public class Address {
public string house_no { get; set; }
public string street { get; set; }
public string zip { get; set; }
}
public class Contact {
public string email { get; set; }
public string ph_no { get; set; }
public Address address { get; set; }
}
//Test program
class Program {
static void GetContacts(string input) {
JavaScriptSerializer serializer = new JavaScriptSerializer();
Dictionary ContactList = serializer.Deserialize>(input);
}
static void Main(string[] args) {
//jsonText is a string that I retrieve from a web service.
string jsonText = ws.GetContactList();
GetContacts(jsonText);
}
}Solution
It is already short and to the point. One minor formatting change; I would make your class properties upper camel case, which is typical for C#. I also dropped the abbreviations.
public class Address {
public string HouseNumber { get; set; }
public string Street { get; set; }
public string Zip { get; set; }
}
public class Contact {
public string Email { get; set; }
public string PhoneNumber { get; set; }
public Address Address { get; set; }
}Code Snippets
public class Address {
public string HouseNumber { get; set; }
public string Street { get; set; }
public string Zip { get; set; }
}
public class Contact {
public string Email { get; set; }
public string PhoneNumber { get; set; }
public Address Address { get; set; }
}Context
StackExchange Code Review Q#1329, answer score: 8
Revisions (0)
No revisions yet.