ADVERTISEMENT
ADVERTISEMENT

C# program to demonstrate the CLSCompliant attribute

Here, we are going to demonstrate the CLSCompliant attribute in C#?
Submitted by Nidhi, on October 31, 2020

Here, we will demonstrate the CLSCompliant attribute. The CLS-compliant attribute is used to generate a warning message when a code element is not CLS compliant.

Program:

The source code to demonstrate the CLSCompliant attribute is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

//C# program to demonstrate the 
//CLSCompliant attribute.

using System; 

[assembly:CLSCompliant(true)]   
public class Sample
{ 
    public uint num; 
} 
  
class Program
{ 
    public static void Main(string[] args) 
    { 
        Console.WriteLine("Hello world"); 
    } 
} 

Output:

Compilation succeeded - 1 warning(s)
Hello world

Explanation:

In the above program, we created the two classes Sample and Program. Here, we used the CLSCompliant attribute with Sample class. Here, the declaration of num data member will generate a warning. Because the CLSCompliant attribute is used to generate a warning message when a code element is not CLS compliant.

The Program class contains the Main() method. The Main() method is the entry point for the program. Here, we printed the "Hello world" message on the console screen.

C# Basic Programs »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.