INTRO:この回答をしばらく探していたが、いくつかの検索にもかかわらずアーカイブ内に見つかりませんでした。あまりにも単純な問題か、Cの法則を破るために何かをしている#二重リンクリスト内のオブジェクトから変数を返す
私は二重にリンクされたリストに新しく、彼らは私の頭をしています!
リスト内のオブジェクトから変数を吐き出すために、二重にリンクされたリストを取得する際に問題があります。
問題を新しいファイルで単純化して頭の中で解決しようとしましたが、DLL内のオブジェクト内の変数を見つけるための正しい構文が見つからないだけです。
私はDLL内の5つのオブジェクトに分割しました。各オブジェクトにはタイトルが付いています。 今、オブジェクトを見つけてタイトルを返すようにしたいと思います。 代わりに:aaaaaaaaaaaaaaaaaaarrrgh!私は間違って何してるの?
namespace ADS
{
public partial class DLL_Generic_Object : Form
{
public DLL_Generic_Object()
{
InitializeComponent();
}
//create class
public partial class Weapon
{
string Title;
public Weapon(string title)
{
this.Title = title;
}
}
//create objects;
Weapon object1 = new Weapon("Revolver");
Weapon object2 = new Weapon("Candlestick");
Weapon object3 = new Weapon("Lead Pipe");
Weapon object4 = new Weapon("Rope");
Weapon object5 = new Weapon("Knife");
public class Structures
{
public string getTitle(LinkedList<Object> nameofDLL)
{
string gotTitle = "How do I Find the Title variable of an Object in the DLL?";
return gotTitle;
}
}
//create an object Doubly Linked List
LinkedList<object> weapons = new LinkedList<object>();
private void btnExecute_Click(object sender, EventArgs e)
{
PrintNodes(weapons); //This will show the DLL is empty.
//Add nodes to the list
weapons.AddFirst(object1); //add a node to the front of the list
//Add a node after a specific node.
weapons.AddAfter(weapons.Find(object1), object2);
weapons.AddAfter(weapons.Find(object2), object4);
//Add a node before a specific node.
weapons.AddBefore(weapons.Find(object4), object3);
//Add a node to the end of the list
weapons.AddLast(object5);
PrintNodes(weapons); // This will show the DLL has 5 Nodes.
// Find the value of a node
}
public string FindTitle(LinkedList<Object> nameofDLL)
{
// initialise a Structures class
Structures structure = new Structures();
// Find the value of a node
string value = structure.getTitle(weapons) + "\r\n";
return value;
}
public void PrintNodes(LinkedList<object> values)
{
if (values.Count != 0) //check if there are any nodes in the list
{
txtOutput.Text += "The number of nodes is: " + values.Count.ToString() + "\r\n";
txtOutput.Text += FindTitle(weapons);
}
else
txtOutput.Text += "The Doubly Linked List is empty" + "\r\n";
}
}
}
リスト内のオブジェクトの種類がわからないときは 'object'を使います。リストに武器だけが含まれているのなら、なぜこれはLinkedListではないのですか? –
フェアコール。私はそれをいくらか一般的に保つようにしていましたが、もしうまくいけばLinkedListをに変更して幸せでした! –