Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8840477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:28:25+00:00 2026-06-14T10:28:25+00:00

So i have this class namespace WindowsFormsApplication2 { public class Records { public string

  • 0

So i have this class

namespace WindowsFormsApplication2
{ 
    public class Records
    {
        public string name, surname;

        public int num;
    }
}

And i want to create an array of this class, tried everything and it still doesn’t work, i started to think it is a bug, i am using Visual Studio 2012, here is my code.Any help would be appreciated.

(there is a datagrid of records on a form, which i’m reading from a textbox, informations are seperated with tab character)

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        Records[] userRecs = new Records[20];

        public int count = 0;


        private void Form1_Load(object sender, EventArgs e)
        {
            getText();
        }

        public void getText() 
        {
            FileStream fs = new FileStream("D:\\filestr.txt",FileMode.Open);

            StreamReader sr = new StreamReader(fs);

            for (string readed = sr.ReadLine(); readed != null; readed = sr.ReadLine())
            {
                string[] tempStr = readed.Split('\t');

                userRecs[count].num = Convert.ToInt32(tempStr[0]);

                userRecs[count].name = tempStr[1];

                userRecs[count].surname = tempStr[2];

                count++;
            }

            for (int i = 0; i < count; i++)
            {
                dataGridView1.Rows.Add(userRecs[count].num, userRecs[count].name, userRecs[count].surname);
            }

            sr.Close();
            fs.Close();
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T10:28:26+00:00Added an answer on June 14, 2026 at 10:28 am

    This allocates memory for the array, but does not create Record instances:

    Records[] userRecs = new Records[20];
    

    Now when you’re iterating through your file lines, you need to instantiate your class:

    userRecs[count] = new Records();
    userRecs[count].num = ...
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this in furniture.h: #include <iostream> #include <string> using namespace std; class Furniture
I have this class: class OriginalClass { string FirstItem; List<string> ListOfSecondItems; } I want
Imagine I have this class namespace CommonLibrary { public class Report() { public DateTime
I want to load this Class library : namespace ClassLibrary1 { public class Class1
I have a data structure that represents C# code like this: class Namespace: string
I have this class public class Address:Entity { public virtual string Address1 { get;
I have this simple example: using System; using System.Collections.Generic; namespace ConsoleApplication1 { class Program
I have a static class that looks like this: namespace Argus { static class
I have a class in my domain model root that looks like this: namespace
I have this class: Class B { private String D; private String E; }

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.