TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Song Lee
NA
47
38.6k
field is never assigned to and will always have its default
Dec 5 2014 5:30 PM
Hmm.. one of my classes is having error with "field is never assigned to and will always have its default value 0" for "m_street""m_zipCode" "m_city" and "m_country;".
I think someone told me to initialize a variable, but I am not sure how to do it.
I tried this, but it didn't work:
private Address m_street = new Address();
/////////// My class below///////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assignment_6_attempt_1
{
/// <summary>
/// Handles addresses. Street, Zip code, City (3) / Street, zip code, city, and country (4)
/// </summary>
class Address
{
//declaring variables
private string
m_street;
private string
m_zipCode;
private string
m_city;
private Assignment_6_attempt_1.ContactFiles.Countries
m_country;
private ContactFiles.Countries Countries;
/// <summary>
/// Default constructor for calling another constructor in this class.
/// </summary>
public Address() : this(string.Empty, string.Empty, "Malmo")
{
this.Street = null;
this.ZipCode = null;
this.City = "Malmo";
}
/// <summary>
/// Constructor with 3 parameters
/// </summary>
/// <param name="street"></param>
/// <param name="zip"></param>
/// <param name="city"></param>
public Address(string street, string zip, string city)
: this(street, zip, city, Assignment_6_attempt_1.ContactFiles.Countries.Sverige)
{
this.Street = street;
this.ZipCode = zip;
this.City = city;
}
/// <summary>
///
/// </summary>
/// <param name="street"></param>
/// <param name="zip"></param>
/// <param name="city"></param>
/// <param name="country"></param>
public Address(string street, string zip, string city, Assignment_6_attempt_1.ContactFiles.Countries country)
{
this.Street = street;
this.ZipCode = zip;
this.City = city;
this.Countries = country;
}
/// <summary>
/// Properties
/// </summary>
public string Street { get; set; }
public string City { get; set; }
public string ZipCode { get; set; }
public Assignment_6_attempt_1.ContactFiles.Countries Country { get; set; }
/// <summary>
/// replaces "_" with space for the country enums
/// </summary>
/// <returns></returns>
public string GetCountryString()
{
string strCountry = m_country.ToString();
strCountry = strCountry.Replace("_", " ");
return strCountry;
}
/// <summary>
/// override the ToString method to return a string made of the address detail
/// </summary>
/// <returns></returns>
public override string ToString()
{
string strOut = string.Format("{0, -25) {1,-8} {2, -10} {3}", m_street, m_zipCode, m_city, GetCountryString());
return strOut;
}
public string GetAddressLabel()
{
string strOut = Street + ZipCode + City + Country;
return strOut;
}
public bool Validate()
{
if (m_street != null)
{
return true;
}
return false;
}
}
}
Reply
Answers (
1
)
Display the file from folder in asp.net using c#
how to connect ms access to godaddy database ?