Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What C# naming scheme can be used for Property & Member that is CLS compliant?

Consider the following code that is not CLS Compliant (differs only in case):

protected String username;

public String Username { get { return username;} set { username = value; } }

So i changed it to:

protected String _username;

public String Username { get { return _username;} set { _username = value; } }

Which is also not CLS-compliant (has leading underscore).

Is there any common naming scheme for members/properties that doesn't violate cls compliance

like image 855
Ian Boyd Avatar asked Nov 26 '11 23:11

Ian Boyd


People also ask

What is C language?

C is a structured, procedural programming language that has been widely used both for operating systems and applications and that has had a wide following in the academic community. Many versions of UNIX-based operating systems are written in C.

What is C language with example?

C language is a system programming language because it can be used to do low-level programming (for example driver and kernel). It is generally used to create hardware devices, OS, drivers, kernels, etc. For example, Linux kernel is written in C. It can't be used for internet programming like Java, .Net, PHP, etc.

What is C -- used for?

C-- is a "portable assembly language", designed to ease the implementation of compilers that produce high-quality machine code. This is done by delegating low-level code-generation and program optimization to a C-- compiler.

What language is C written in?

It was based on CPL (Combined Programming Language), which had been first condensed into the B programming language—a stripped-down computer programming language—created in 1969–70 by Ken Thompson, an American computer scientist and a colleague of Ritchie.


1 Answers

Rather than exposing the backing field, make your property virtual so inheritors can override the functionality without exposing the implementation of your backing field.

private String username;

public virtual String Username { get { return username;} set { username = value; } }

Inherits shouldn't have to know anything your classes implementation.

See Best way to expose protected fields

like image 189
shf301 Avatar answered Sep 21 '22 15:09

shf301