-1

this is a nodeJs code for creating an array Of teacher in a Course Model

  teacher: {
    fullName: String,
    email: String,
    _id: ObjectId,
    profile: String,
},

I want to Create this in Asp,.Net Core

how Should I Do it ?

I can create a StringArray like this

public string[] Teacher {get; set;}

But I dont know how to set that details into it

3
  • 1
    You need to create Teacher class with the properties. Commented Aug 1, 2022 at 9:55
  • That Node code isn't an array, it's just an object. Commented Aug 1, 2022 at 10:01
  • 1
    Does this answer your question? Define a List of Objects in C# Commented Aug 1, 2022 at 10:07

1 Answer 1

1

You're showing us your model in TypeScript. First you've to convert that model to a .net class. Which would result into something like:

public class Teacher
{
    public string Id { get; set; }
    public string FullName { get; set; }
    public string Email { get; set; }
    public string Profile { get; set; }
}

Next you've to create a list or array of this model, since you said you had an array in JavaScript I will use it as well. So you will get:

Teacher[] teachers = new Teacher[5];

Next you want to set a value in this array (there are multiple ways how you can do this), one way of doing this is:

teachers[0] = new Teacher
{
    Id = "1",
    FullName = "Full Name",
    Email = "[email protected]",
    Profile = "Some profile information"
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.