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 1018499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:52:01+00:00 2026-05-16T10:52:01+00:00

I’m trying to retrieve odd values in a List of strings and convert them

  • 0

I’m trying to retrieve odd values in a List of strings and convert them into a Guid Object. Here is what i came up with

        Guid oGuid = new Guid();
        string objectName = string.Empty;

        for (int i = 0; i < lst_objectName_Guid.Count; i++)
        {
            if (i % 2 != 0) //The GUID values are in the Odd-Numbered Indexses
            {
                oGuid = new Guid(lst_objectName_Guid[i]); //Convert the GUID Values from string to Guid
            }
            else
            {
                objectName = lst_objectName_Guid[i];    //Assign the objectName Values into a string variable
            }

            Console.WriteLine(objectName);
            Console.WriteLine(oGuid);

The problem is now that always it displays a set of (0) Zero’s as the first Guid is retrieved and I get a “Object does not exist” when I check if the Object is locked or not.(I get this on every even object that is tested)

Can anybody tell me what’s happening and why? and if there is a better way to retrieve odd_numbered indexes and store them as GUID

I’m pretty sure that the odd indexes hold the Guid Values as strings. I printed out the List and made sure of that

Thanks

  • 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-05-16T10:52:01+00:00Added an answer on May 16, 2026 at 10:52 am

    I think Grzenio’s answer is correct, but I don’t think you’re understanding why. To elaborate, take this simple example:

    string Part1 = "";
    string Part2 = "";
    
    for (int i = 0; i < 2; i++)
    {
        if (i == 0)
        {
            Part1 = "Set on first iteration";
        }
        else
        {
            Part2 = "Set on second iteration";
        }
    }
    

    Now, this is exactly what you’ve done. On the first iteration of the loop (i==0), you’re only setting the first variable Part1. So the output would be:

    Part1: "Set on first iteration"
    Part2: ""
    

    On the second iteration (i==1), Part2 will have it’s value set and then it would ouput:

    Part1: "Set on first iteration"
    Part2: "Set on second iteration"
    

    So, taking your example:

    Guid oGuid = new Guid(); // Equals all 0s by default
    string objectName = string.Empty;
    

    objectName gets set on the first iteration, but oGuid does not. Hence why oGuid remains “all zeros” (Guid.Empty).

    So, this should be the code you use:

    Guid oGuid = new Guid();
    string objectName = string.Empty;
    
    for (int i = 0; i < lst_objectName_Guid.Count; i+=2)
    {
    
        // Notice how BOTH variables are assigned
        oGuid = new Guid(lst_objectName_Guid[i]); 
        objectName = lst_objectName_Guid[i + 1];
    
        // So when they're written to the console, they both have values
        Console.WriteLine(objectName);
        Console.WriteLine(oGuid);
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.