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

  • SEARCH
  • Home
  • 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 8930969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:00:30+00:00 2026-06-15T09:00:30+00:00

I am reading a file and information is provided line by line (this I

  • 0

I am reading a file and information is provided line by line (this I can’t change). I want to create an object if the line has x value and if the line has y value, assign some values to the object. this proves to be very challenging. obviously I am doing something wrong.

if (line_split[i].Contains("LabelId"))
{
   try
   {
       gen.m_LabelId_pos.Add(multicast_ports[3], i);
       multicast my_multicast = new multicast();
   }
   catch
   {
   }
}
else if (line_split[i].Contains("TotalFrameSentCount_PerSecond"))
{
    try
    {                                    
        gen.m_TotalFrameSentCount_PerSecond_pos.Add(multicast_ports[3], i);
        // want to assign y value to the object here. but cant
    }
    catch
    {
    }
}
  • 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-15T09:00:31+00:00Added an answer on June 15, 2026 at 9:00 am

    You can declare the object outside of the if statement, instantiate it in the if block and set it’s value in the else block after you have checked that it isn’t null. Something like this:

    multicast my_multicast = null;
    if (line_split[i].Contains("LabelId"))
    {
       try
       {
           gen.m_LabelId_pos.Add(multicast_ports[3], i);
           my_multicast = new multicast();
       }
       catch
       {
       }
    }
    else if (line_split[i].Contains("TotalFrameSentCount_PerSecond"))
    {
        try
        {                                    
            gen.m_TotalFrameSentCount_PerSecond_pos.Add(multicast_ports[3], i);
            if(my_multicast!=null)
            {
                //do something with my_multicast here
            }
        }
        catch
        {
        }
    }
    

    As an aside note, you should avoid eating your Exceptions, they are meant to help you if something goes wrong, this way catch block will hide them and you won’t have a clue what went wrong. Use

    catch(Exception err)
    {
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A text file holds information about a softball team. Each line has data arranged
I'm reading a file and each line has a tag, followed by a colon
i just create reading file feature. In general, what kind PHP class that usually
I am reading a file by character but I want to skip number of
I'm reading a file using bufferedreader, so lets say i have line = br.readLine();
I am reading a file byte-by-byte. Say for example i have this byte: 0x41
---edit--- Is there any additional information I can give to help solve this problem?
Is there an easy way to see whether particular file has DOS/MAC/UNIX line endings?
I'm reading a csv file and insert the information in a sql 2005 database.
Reading from the googleVis package vignette : With the googleVis package users can create

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.