C#函数编译出错:Inconsistent accessibility: parameter type ‘aaa.bbb.ccc’ is less accessible than method ‘aa
来源:互联网 发布:韩火火的淘宝店叫什么 编辑:程序博客网 时间:2024/05/16 09:27
C#的函数:
//save product info public void saveProductInfo(AmazonProductInfo productInfo) { return; }
被别处调用:
//check whether each product valid or not //if valid, extract product info //http://www.amazon.com/Silver-Linings-Playbook/dp/B00CL68QVQ/ref=sr_1_2?s=instant-video&ie=UTF8&qid=1368688342&sr=1-2 private void checkAndExtractForSingleProduct(string productUrl) { bool isProductValid = false; string invalidReason = ""; //string respHtml = crl.getUrlRespHtml(productUrl); string productHtml = crl.getUrlRespHtml_multiTry(productUrl); string usedAndNewUrl = ""; isProductValid = checkProductValid(productUrl, productHtml, out invalidReason, out usedAndNewUrl); if (isProductValid) { AmazonProductInfo productInfo = extractProductInfo(productUrl, productHtml, usedAndNewUrl); saveProductInfo(productInfo); } }
涉及到的结构体定义为:
struct AmazonProductInfo { public string title; public string description; //5 bullet public string[] bulletArr; // total 5 //download 5 pics public string[] imgFullnameArr; // total 5 //product keyword, up to 5 //public string keyword1; //public string keyword2; //public string keyword3; //public string keyword4; //public string keyword5; //highest price of total (up to 8) sellers public float highestPrice; public bool isOneSellerIsAmazon; public int reviewNumber; public bool isBestSeller; };
结果编译出错:
Error 1 Inconsistent accessibility: parameter type ‘ScrapeAmazonProduct.frmScrapeAmazonProduct.AmazonProductInfo’ is less accessible than method ‘ScrapeAmazonProduct.frmScrapeAmazonProduct.saveProductInfo(ScrapeAmazonProduct.frmScrapeAmazonProduct.AmazonProductInfo)’ D:\tmp\tmp_dev_root\freelance\elance\40939187_scrape_amazon\40939187_scrape_amazon\ScrapeAmazonProduct\ScrapeAmazonProduct\frmScrapeAmazonProduct.cs 648
【解决过程】
1.注意到,已经把原先的函数加上public了。
但是还是出错。
2.参考:
Inconsistent Accessibility: Parameter type is less accessible than method
去把原先的结构体:
struct AmazonProductInfo { public string title; public string description; //5 bullet public string[] bulletArr; // total 5 //download 5 pics public string[] imgFullnameArr; // total 5 //product keyword, up to 5 //public string keyword1; //public string keyword2; //public string keyword3; //public string keyword4; //public string keyword5; //highest price of total (up to 8) sellers public float highestPrice; public bool isOneSellerIsAmazon; public int reviewNumber; public bool isBestSeller; };
也加上public:
public struct AmazonProductInfo { public string title; public string description; //5 bullet public string[] bulletArr; // total 5 //download 5 pics public string[] imgFullnameArr; // total 5 //product keyword, up to 5 //public string keyword1; //public string keyword2; //public string keyword3; //public string keyword4; //public string keyword5; //highest price of total (up to 8) sellers public float highestPrice; public bool isOneSellerIsAmazon; public int reviewNumber; public bool isBestSeller; };
试试,结果就解决问题了。
3.但是还是很诡异,因为此处,不论是函数:
saveProductInfo
函数其中的参数:
AmazonProductInfo
还是调用该函数的其他函数:
checkAndExtractForSingleProduct
都是在当前的cs文件内,都是属于命名空间:
ScrapeAmazonProduct.frmScrapeAmazonProduct
的。
所以,应该不存在此类错误的。
4.后来把原先的函数saveProductInfo,从public改为private
同时去掉结构体AmazonProductInfo的public:
struct AmazonProductInfo{ public string title; public string description; //5 bullet public string[] bulletArr; // total 5 //download 5 pics public string[] imgFullnameArr; // total 5 //product keyword, up to 5 //public string keyword1; //public string keyword2; //public string keyword3; //public string keyword4; //public string keyword5; //highest price of total (up to 8) sellers public float highestPrice; public bool isOneSellerIsAmazon; public int reviewNumber; public bool isBestSeller;};//save product infoprivate void saveProductInfo(AmazonProductInfo productInfo){ return;}private void checkAndExtractForSingleProduct(string productUrl){ ...... saveProductInfo(productInfo); ......}
结果也是可以的。
至此,才算明白内部的逻辑。
【总结】
下列情况:
struct structA //default here is private{ ......};//save product infopublic void funA(structA structValue){ return;}private void funcB(string productUrl){ ...... funA(structValue); ......}
会出现此处的编译错误提示:
Inconsistent accessibility: parameter type xxx is less accessible than method yyy的原因:
funcB调用funcA,本来是没问题的,但是,由于funcB是private,调用的funcA是public,并且传递的参数structA是private,所以可能会出现:
structA是属于private的funcB的,而无法被funcA访问到。
解决办法:
要么把funcA改为private,则此时,两个函数都是private,而对应的structA是public,也都可以访问到了:
public struct structA{ ......};//save product infoprivate void funA(structA structValue){ return;}private void funcB(string productUrl){ ...... funA(structValue); ......}
要么把structA改为public,使得不论是private的funcB还是public的funcA都访问到:
public struct structA{ ......};//save product infopublic void funA(structA structValue){ return;}private void funcB(string productUrl){ ...... funA(structValue); ......}
结论:
以后对于函数和结构体等,还是要注意设置合适的权限,即统一的private或public,不要不小心搞混乱了。
- C#函数编译出错:Inconsistent accessibility: parameter type ‘aaa.bbb.ccc’ is less accessible than method ‘aa
- Inconsistent accessibility: field type '...' is less accessible than field '...'
- Error 1 Inconsistent accessibility: parameter type C#编译时候出错
- C# Inconsistant accessibility:property type "XXX" is less accessible than property "XXX"
- Error 1 Inconsistent accessibility: parameter type 编译错误
- Error 1 Inconsistent accessibility: parameter type 编译错误
- 【C#】Error 1 Inconsistent accessibility: parameter type C#错误原因
- c#编译错误Inconsistent accessibility
- c#编译错误Inconsistent accessibility
- echo "/aaa/bbb/ccc" | sed 's/.*\///g'
- 编译错Inconsistent accessibility
- 编译错Inconsistent accessibility
- Java编译错误“No enclosing instance of type AA is accessible. Must qualify the alloc
- Java编译错误“No enclosing instance of type AA is accessible. Must qualify the allocation with an enclosi
- Java编译错误“No enclosing instance of type AA is accessible. Must qualify the allocation with an enclosi
- 语法求救 ifneq ($(filter aaa bbb ccc, $(Var)),)
- Java编译错误“No enclosing instance of type AA is accessible. Must qualify the allocation with an enclosing instance of type SimpleTh
- Java编译错误“No enclosing instance of type AA is accessible. Must qualify the allocation with an enclosing instance of type SimpleTh
- ANN(人工神经网络)基础知识
- 探索性测试ET(Exploratory Test)
- 1-初始Zookeeper
- iOS静态库的打包-徐明伟
- HttpClient已过时,访问网络用HttpURLConnection
- C#函数编译出错:Inconsistent accessibility: parameter type ‘aaa.bbb.ccc’ is less accessible than method ‘aa
- 1321. Robot
- Android——AsyncTask(异步)简介
- adb操作命令详解及大全
- Js中把JSON字符串转换为JSON对象(eval()、new Function())
- 广告统计数据恢复改进及实现
- WebView的用法
- 事务的概念和四大特性以及事务的隔离级别
- es6 javascript的Proxy及拦截操作一览