C# 不包含定义或扩展方法
我尝试构建时遇到下一个错误: 不包含定义或扩展方法 我有一门课是这样的:C# 不包含定义或扩展方法,c#,.net,compiler-errors,C#,.net,Compiler Errors,我尝试构建时遇到下一个错误: 不包含定义或扩展方法 我有一门课是这样的: [Serializable] public class JobFile { private FileInfo mFileInfo; private string mJobNumber = string.Empty; private string mBaseJobNumber = string.Empty; private Guid mDocumentTytpeid = Guid.Em
[Serializable]
public class JobFile
{
private FileInfo mFileInfo;
private string mJobNumber = string.Empty;
private string mBaseJobNumber = string.Empty;
private Guid mDocumentTytpeid = Guid.Empty;
public string DocumentTypeDescription
{
get
{
string description;
DocumentType DocType;
DocType = DocumentType.GetDocType(DocumentTypeCode);
if (DocType.Code == null)
description = "Unknown";
else
description = DocType.Description;
return description;
}
}
public Guid DocumentTypeID
{
get
{
DocumentType DocType;
DocType = DocumentType.GetDocType(DocumentTypeCode);
if (DocType.Code == null)
mDocumentTytpeid = Guid.Empty;
else
mDocumentTytpeid = DocType.Id;
return mDocumentTytpeid;
}
}
现在,我尝试在另一个类中获取Documenttypeid的值,如下所示:
foreach (FileInfo fi in files)
{
JobFile jf = null;
jf = new JobFile(ref fi);
f.DocumentTypeId = jf.DocumentTypeID; //<-- error is here
}
foreach(文件中的文件信息)
{
JobFile jf=null;
jf=新作业文件(参考fi);
f、 DocumentTypeId=jf.DocumentTypeId;//问题在于f.DocumentTypeId
假设它也是一个作业文件
,那么它应该是f.DocumentTypeID
(注意ID不是ID)。
C#区分大小写。此外,只有get
属性访问器,而不是set
如果f
是其他类型,请向我们显示代码。错误消息非常清楚错误所在。您正在尝试使用一个不存在的属性,并查看错误是如何在此行发生的:
f.DocumentTypeId = jf.DocumentTypeID;
这只能是两件事之一:
f
不存在
f.DocumentTypeId
不存在
jf.DocumentTypeID
不存在
老实说,我会检查以确保f.DocumentTypeId
不应该是f.DocumentTypeId
.C#对这样的事情很挑剔,这样的一个小错误会导致你收到的错误。在f.DocumentTypeId
中,f
的类型是什么e循环?不应该是fi
?请发布完整的错误文本。并自己格式化代码,它是不可读的。抱歉,F是另一个名为file.cs的类的定义。我想设置Documenttypeid=无论jf.Documenttypeid是什么。我们需要查看file.cs,以及F是什么类型的定义。谢谢,F实际上是另一个r类,很抱歉,我没有把那部分放在那里,我只是想简明扼要。我正在file.cs类(f)中设置变量,以便在那里进行插入。如果f
的类型是JobFile
,那么我的答案应该可以解决您的问题。它不是f的类型file(Library.file.file f=new Library.file();)编译器告诉您,Library.File.File
不包含DocumentTypeId
的定义。如果不知道您预期会发生什么,也不知道Library.File.File
的定义是什么,我们就帮不上什么忙了。@ElPollo:我同意乔治的观点。错误非常清楚;您的属性是尝试获取或设置不存在。