开发者

function is inaccessible due to its protection level

开发者 https://www.devze.com 2023-04-12 09:14 出处:网络
I am having an issue with C# in ASP. I get an error on the following line of code which starts \"string[]\"....

I am having an issue with C# in ASP.

I get an error on the following line of code which starts "string[]"....

Label DT33 = (Label)MainContent2.FindControl("data_text");

string[] lines = Strings.Split(DT33.Text, "<br>");
num = lines.Length;The error reads....

Compilation Error Descripti开发者_Go百科on: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0122: 'System.Linq.Strings' is inaccessible due to its protection level

I have specified the following names space....

using Microsoft.VisualBasic;

Along with many others. This is a .net 3.5 app, I am out of ideas at this point.

thanks,


I take it you actually mean this:

Label DT33 = (Label)MainContent2.FindControl("data_text");

string[] lines = DT33.Text.Split(new string[] {"<br>"}, StringSplitOptions.None);
num = lines.Length;

The reason why you get the (somewhat cryptic) error message is because System.Linq apparently has an internal class called Strings.


Your problem is the following line:

string[] lines = Strings.Split(DT33.Text, "<br>");

You've added an extra 's' on to String. I'm guessing you're also including System.Linq which apparently has a private/internal class (which is inaccessible to you) called Strings. Hence the error message about Strings being inaccessible due to protection level.

You just need to change the offending line to:

string[] lines = DT33.Text.Split(new string[] { "<br>" },
                                 StringSplitOptions.None);

And you should be good to go.


You are trying to use Microsoft.VisualBasic.Strings.Split, but your usage is conflicting with another Strings class that is available.

Try fully qualifying your method call.

string[] lines = Microsoft.VisualBasic.Strings.Split(text, separator);

However, you should also consider using the string.Split instance method available for System.String directly. Evaluate its behavior and see if you can use it instead, as using basic BCL methods in C# is more idiomatic than using methods more or less specific to Visual Basic.

http://msdn.microsoft.com/en-us/library/y7h14879.aspx

So you might have something like

string[] lines =  yourText.Split(new string[] { "<br>" }, StringSplitOptions.RemoveEmptyEntries);


I think you want

string.Split(.....)

rather than Strings


In my case, I was trying to use LINQ Dynamic Query Library or System.Linq.Dynamic.DynamicExpression. You can get it from this link.

More details on ScottGu's blog here

0

精彩评论

暂无评论...
验证码 换一张
取 消