2016-06-01 1 views
0

initilization私は、文字列を初期化することだし、それはとNullReferenceExceptionを投げています:別の部分では文字列とNullReferenceException

string HTML = 
     "<div class=\"table-responsive formMOE\">" + 
     "<table class=\"table\">" + 
     "<thead class=\"white\"><tr><th>Name</th><th>Description</th><th>Price</th></tr></thead>" + 
     "<tbody data-link=\"row\" class=\"rowlink\">"; 

と全くとNullReferenceExceptionを取得していない:私はこのコードを使用していても

string HTML = 
      "<div class=\"table-responsive formMOE\">" + 
      "<table class=\"table\">" + 
      "<thead class=\"white\"><tr><th>ID</th><th>Name</th><th>Type</th><th>Description</th><th>Ingredients</th><th>Price</th></tr></thead>" + 
      "<tbody data-link=\"row\" class=\"rowlink\">" + 
      "<tr>" + 
      "<td><a href=\"Products.aspx?ProductID=" + product.ProductID + "\"></a>" + product.ProductID + 
      "</td><td>" + product.Name + 
      "</td><td>" + product.Type + 
      "</td><td>" + product.Description + 
      "</td><td>" + product.Ingredients + 
      "</td><td>" + product.Price + 
      " <span class=\"fa fa-shekel\"></span></td><td>" + 
      "</td>" + 
      "</tr>" + 
      "</tbody></table></div>"; 

を。

"hi"のようなランダムな値に文字列を設定して、実際の値に設定しようとしましたが、動作しませんでした。

+2

'product'はnullです。 – Jamiec

+0

@Jamiecあなたはそうです、私は決してそれに遭遇していないので、私はそれを考えなかった。ありがとうございました。 – Mohanad

答えて

2

私が見ることができる唯一の問題は、あなたの製品オブジェクトがヌルであることです。

第1

string HTML = 
"<div class=\"table-responsive formMOE\">" + 
"<table class=\"table\">" + 
"<thead class=\"white\"><tr><th>Name</th><th>Description</th><th>Price</th></tr></thead>" + 
"<tbody data-link=\"row\" class=\"rowlink\">"; 

ヌル例外を生成することができません。

テスト済み:http://www.tutorialspoint.com/compile_csharp_online.php?PID=0Bw_CjBb95KQMVjhidVFDdGJYd1U

関連する問題