我正在创建一个代码,该代码接收地址和地址的平方。我正在使用列表和集合通用。它只返回房子+地方六次。请帮忙
using System;
using System.Collections.Generic;
using System.Linq;
class House
{
class place
{
public string address { get; set; }
public int sqft { get; set; }
public place(string address, int sqft)
{
this.address = address;
this.address = address;
}
}
public static void Main(string[] args)
{
List<place> places = new List<place>();
places.Add(new place("lewis Rd.", 2001));
places.Add(new place("mike Rd.", 1500));
places.Add(new place("deseree St.", 1250));
places.Add(new place("bottle Dr.", 2500));
places.Add(new place("pen St.", 1100));
places.Add(new place("walton St.", 999));
for (int i = 0; i < places.Count; i++)
{
Console.Write(" {0}\n", places[i]);
}
Console.ReadKey();
}
}
答案 0 :(得分:2)
我没有得到构造函数错误,但有两个问题需要解决。
您的Console.Write行没有指定要输出的属性,应该更接近这个...
StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
String algorithm = "PBEWITHSHA256AND256BITAES-CBC-BC";
String providerName = "BC";
encryptor.setAlgorithm(algorithm);
encryptor.setProviderName(providerName);
String encData = EMPTY_STRING;
try{
encryptor.setPassword("myPassword");
encData = encryptor.encrypt(dataToEncrypt);
}
您还要分配地址两次......
Console.Write(" {0} has {1} square feet\n", places[i].address, places[i].sqft);
......当你可能想要的时候
this.address = address;
this.address = address;