Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# array of class

public static class Exercise
{
    static int Main(string[] args)
    {
        var StaffMembers = new Employee[3];

        StaffMembers[0] = new Employee();
        StaffMembers[0].EmployeeNumber = 20204;
        StaffMembers[0].EmployeeName = "Harry Fields";
        StaffMembers[0].Status = EmploymentStatus.FullTime;
        StaffMembers[0].HourlySalary = 16.85;

        StaffMembers[1] = new Employee();
        StaffMembers[1].EmployeeNumber = 92857;
        StaffMembers[1].EmployeeName = "Jennifer Almonds";
        StaffMembers[1].Status = EmploymentStatus.FullTime;
        StaffMembers[1].HourlySalary = 22.25;

        StaffMembers[2] = new Employee();
        StaffMembers[2].EmployeeNumber = 42963;
        StaffMembers[2].EmployeeName = "Sharon Culbritt";
        StaffMembers[2].Status = EmploymentStatus.PartTime;
        StaffMembers[2].HourlySalary = 10.95;

        return 0;
    }
}
Comment

c# array of objects

T[] InitializeArray<T>(int length) where T : new() {
    T[] array = new T[length];
    for (int i = 0; i < length; ++i) {
        array[i] = new T();
    }
    return array;
}

// Usage:
MyObjects[] my_objects = InitializeArray<MyObjects>(10);
Comment

array of objects c#

// we will call 'Person' an object
Person[] personArr = new Person[10];
Person[,] person2DArr = new Person[10,10];
Comment

PREVIOUS NEXT
Code Example
Csharp :: C# scrape html document 
Csharp :: C# traverseall elements in class property 
Csharp :: how to serialize a property in unity 
Csharp :: c# loop 2 time tables 
Csharp :: C# ValidationAttribute required when 
Csharp :: C# top down view player movement 
Csharp :: unity c# destroy gameobject 
Csharp :: interop C# save as and replace 
Csharp :: extension method in c# 
Csharp :: how to check if a file is running in c# 
Csharp :: unity deactivate scripts in list 
Csharp :: print hello world in unity 
Csharp :: c# dictionary check if value exists 
Csharp :: unity stop velocity movement 
Csharp :: load a form from button c# 
Csharp :: convert word files to plain text c# 
Csharp :: JavaScriptSerializer() and convert to base64 
Csharp :: array in c# 
Csharp :: concatenate two lists in c# 
Csharp :: ##[error]Dotnet command failed with non-zero exit code on the following projects 
Csharp :: how to instantiate and delete unity 
Csharp :: How to set default page asp.net MVC 
Csharp :: unity save scene at runtime 
Csharp :: C# Console font 
Csharp :: c# HttpResponseMessage postResponse = client.PostAsync 
Csharp :: datetime show 24 hour format c# 
Csharp :: c# dapper execute stored procedure with parameters 
Csharp :: while loop in c# 
Csharp :: blazor use static json files 
Csharp :: create anchor tag dynamically c# 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =