I am wondering if a struct is like an object or is an object.
For example a struct:
struct Books
{
public string title;
public string author;
public string subject;
public int book_id;
};
Defining this struct:
public class testStructure
{
public static void Main(string[] args)
{
Books Book1; /* Declare Book1 of type Book */
Books Book2; /* Declare Book2 of type Book */
/* book 1 specification */
Book1.title = "C Programming";
Book1.author = "Nuha Ali";
Book1.subject = "C Programming Tutorial";
Book1.book_id = 6495407;
/* book 2 specification */
Book2.title = "Telecom Billing";
Book2.author = "Zara Ali";
Book2.subject = "Telecom Billing Tutorial";
Book2.book_id = 6495700;
}
}
This is similar to how an object is created for example the class dog:
class dog
{
public String Name;
public String Sound;
}
and creating objects of class dog and defining:
private void button1_Click(object sender, EventArgs e)
{
dog dogObj1 = new dog();
dogObj1.Name = "dog1";
dogObj1.Sound = "Woof";
dog dogObj2 = new dog();
dogObj2.Name = "dog2";
dogObj2.Sound = "Woof";
}
As you can see objects and structs are similar in structure.
Are structs actually a type of object?