I get the warning like this If you know what it is, please explain & help me to get rid of it. Nam.
CLS compliance has to do with interoperability between the different . NET languages. The property is not CLS compliant, because it starts with an underscore and is public (note: protected properties in a public class can be accessed from outside the assembly).
Being CLS compliant means that you can write code that can be consumed by any language that can be compiled and run on the CLR. But CLS compliance is not required, giving you the flexibility in cases where CLS compliance would be hard or impossible to do.
In your AssemblyInfo.cs file, you've probably got a line that reads
[assembly:CLSCompliant(true)]
If you do, then the following rules must be met. (Copy-Pasta from http://www.devarticles.com/c/a/C-Sharp/Making-Your-Code-CLS-Compliant/)
Unsigned types should not be part of the public interface of the class. What this means is public fields should not have unsigned types like uint or ulong, public methods should not return unsigned types, parameters passed to public function should not have unsigned types. However unsigned types can be part of private members.
Unsafe types like pointers should not be used with public members. However they can be used with private members.
Class names and member names should not differ only based on their case. For example we cannot have two methods named MyMethod and MYMETHOD.
Only properties and methods may be overloaded, Operators should not be overloaded.
This is an old question, but I thought a better explanation was due for future investigators (such as myself).
First off, the links in the other answers provide great detail into the reason this warning is given.
However, to summarize, code written for the Common Language Runtime (such as C#) is CLS-Compliant if it can interface with other languages designed for the CLR. This means that certain datatypes specific to the language that are not common to the entire runtime are not compliant. The quick and easy fix for this in regards to variables and methods is to give them the visibility modifier internal
which specifies that the method, class, property, etc. is not visible outside of the assembly it is being built for. This should only be done on those items which you do not need or want to be used outside of the assembly; for those that you want visible, use datatypes that are CLS-compliant.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With