In: Computer Science
Below is the class library code.
using System;
namespace MyClassLibrary
{
public class MyLibraryClass
{
//Fields
private string name;
private int age;
private int _rollNumber;
// Auto-implemented properties
public string Division { get; set; }
//Read Write Property. It has both get and set accessor hence considered as read/write properties.
public int RollNumber
{
get
{
return _rollNumber;
}
set
{
_rollNumber = value;
}
}
//Read only property
public string TestMessage
{
get
{
return "Hello!";
}
}
//Default constructor
public MyLibraryClass()
{
}
//Parameteric constructor
public MyLibraryClass(int rollNumber, string division)
{
this.RollNumber = rollNumber;
this.Division = division;
}
public MyLibraryClass(string stateName, string country)
{
this.StateName = stateName;
this.CountryName = country;
}
//Method with zero parameter.
public int getSquareOfTwo()
{
int square = 2 * 2;
return square;
}
//Method with two parameters
public int getMultiplication(int a, int b)
{
int multiplication = a * b;
return multiplication;
}
//expression-body properties
public string StateName { get; set; }
public string CountryName { get; set; }
public string CountryState => $"{CountryName} {StateName}";
}
}
Follow below step to create class library.
Open visual studio
Create new project
Under Visual C#, Create class library.
Give Name as per your choice