Q:

C# program to check a specified class is a serializable class or not

0

C# program to check a specified class is a serializable class or not

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

The source code to check a specified class is a serializable class or not is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

//C# program to check a specified class 
//is a serializable class or not.

using System;
using System.Reflection;

[Serializable]
class Sample
{ 
    public static void Print()
    {
        Console.WriteLine("Print() method called");
    }
}

class Program
{
    static void Main()
    {
        Type type = typeof(Sample);

        if (type.IsSerializable == true)
        {
            Console.WriteLine("Sample is a serializable class");
        }
        else
        {
            Console.WriteLine("Sample is not a serializable class");
        }
    }
}

Output:

Sample is a serializable class
Press any key to continue . . .

Explanation:

In the above program, we created two classes Sample and Program. The Sample is a serializable class that contains a static Method Print(), and the Program class contains the Main() method. The Main() method is the entry point for the program. Here, we check the specified class is a serializable class or not using the IsSerializable property of Type class and printed the appropriate message on the console screen.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# Basic Programs | Class, Object, Methods

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C# program to check a class is a sub-class of a sp... >>
<< C# program to check a specified class is a sealed ...