トピックからリソースIDを使用しようとすると、アプリケーションを作成するときにいくつかあります このエラーが発生します NullReferenceException 私の質問は、NullReferenceExceptionなしでトピックオブジェクトのデータ型としてリソースを使用する方法です
System.NullReferenceException was unhandled
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=test
StackTrace:
at test.Program.Main(String[] args) in C:\Users\Abdalla\Desktop\BOL\BOL\test\Program.cs:line 17
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BOL;
namespace test
{
class Program
{
static void Main(string[] args)
{
Topic t = new Topic();
t.Id = 1;
t.Drescription = "Topic Drescription ";
t.Resource.ResourceID = 1;
Console.WriteLine("ResourceID" + t.Resource.ResourceID.ToString());
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BOL
{
class Topic
{
public int Id { get; set; }
public int Drescription { get; set; }
public Resource Resource { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BOL
{
class Resource
{
public int ResourceID { get; set; }
public string Res_summary { get; set; }
public string PageID { get; set; }
public Guid UserID { get; set; }
public bool Enabled { get; set; }
public Resource() { }
}
}