If you want to share code between applications, then you'll need to create a "class library" project, and reference it from both applications.
Create a .NET class library using Visual Studio - .NET | Microsoft Learn[
^]
In the class library:
using System;
using System.Data;
namespace MyClassLibrary
{
public static class MySampleData
{
public static DataTable GetTable()
{
DataTable table = new DataTable();
table.Columns.Add("Dosage", typeof(int));
table.Columns.Add("Drug", typeof(string));
table.Columns.Add("Diagnosis", typeof(string));
table.Columns.Add("Date", typeof(DateTime));
table.Rows.Add(25, "Drug A", "Disease A", DateTime.Now);
table.Rows.Add(50, "Drug Z", "Problem Z", DateTime.Now);
table.Rows.Add(10, "Drug Q", "Disorder Q", DateTime.Now);
table.Rows.Add(21, "Medicine A", "Diagnosis A", DateTime.Now);
return table;
}
}
}
In application 1:
using System;
using System.Data;
using MyClassLibrary;
static class Program
{
static void Main()
{
DataTable table = MySampleData.GetTable();
Console.WriteLine("FIRST ROW, DOSAGE: {0}", table.Rows[0]["Dosage"]);
}
}
In application 2:
using System;
using System.Data;
using MyClassLibrary;
static class Program
{
static void Main()
{
DataTable data = MySampleData.GetTable();
foreach (DataRow row in data.Rows)
{
Console.WriteLine(row.Field<int>(0));
}
}
}