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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:31:56+00:00 2026-05-14T06:31:56+00:00

I’m new to C#, so this may be a basic question. What I need

  • 0

I’m new to C#, so this may be a basic question. What I need to do is put an array such as the one below in a class library and then make a call to it. So I’d want the appropriate picture to appear via the class and this array. I know there’s a much simpler way to make certain pictures appear, but this is a requirement for the project. It’s an asp.NET website in C#.

string[] PictureArray;

PictureArray = new string[3];
PictureArray[0] = "~/pics/grl.jpg";
PictureArray[1] = "~/pics/pop.jpg";
PictureArray[2] = "~/pics/str.jpg";
PictureArray[3] = "~/pics/unk.jpg";

EDIT (also in comment):
I’m trying to get the picture from the array to show up in an image box upon a button click like this:

protected void Button1_Click(object sender, EventArgs e) { 
   Class1 name = new Class1(); 
   this.Image1.ImageUrl = name.GetPic(); 
}

Obviously just the name.GetPic() isn’t going to do anything, it’s throwing an error actually.

EDIT2: Sorry for the confusion, I just realized I can edit and comment. I’ve got the array in the class properly setup, now I need to access it (read above edit).

Answered

string[] pictures = work.GetPictures();
Image1.ImageUrl = pictures[0];

is all that I needed to see, thanks Zyphrax

  • 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-14T06:31:57+00:00Added an answer on May 14, 2026 at 6:31 am

    ok, it seems that you’ve put some effort into this.
    I think you’re looking for something like the sample below.

    I’ve added comments to help you understand what’s going on.

    One of the classes in your class library:

    // Define a class called HomeWork, make it accessible to other
    // classes in other namespaces
    public class HomeWork {
    
      // Define a method called GetPictures, no incoming arguments,
      // returns a string[]
      public string[] GetPictures() {
    
        // Create a new instance of a string array
        string[] pictures = new string[4];
    
        // Fill the string array with a couple of strings
        pictures[0] = "~/pics/grl.jpg";
        pictures[1] = "~/pics/pop.jpg";
        pictures[2] = "~/pics/str.jpg";
        pictures[3] = "~/pics/unk.jpg";
    
        // Return the string array
        return pictures;
      }
    }
    

    How to call the method on that class:

    // Create a new instance of the HomeWork class
    HomeWork work = new HomeWork();
    
    // Call the GetPictures method
    work.GetPictures();
    

    Please ask your teacher to explain it into more detail.
    We can’t teach you years of programming experience in one SO question 🙂

    EDIT: In response to your second question

    Option 1: use the array that was returned by GetPictures:

    HomeWork work = new HomeWork();
    string[] pictures = work.GetPictures();
    
    Image1.ImageUrl = pictures[0];
    Image2.ImageUrl = pictures[1];
    Image3.ImageUrl = pictures[2];
    // etc..
    

    Option 2: create an overload for GetPictures that accepts an index

    public string[] GetPictures() {
        // This method remains unchanged
    }
    
    public string[] GetPictures(int index) {
       // Get the string array from GetPictures
       string[] pictures = GetPictures();
    
       // Return a specific index
       return pictures[index];
    
       // As you can see, this method might be
       // dangerous to use, because someone could
       // ask for an invalid index causing an
       // IndexOutOfRangeException
    }
    
    HomeWork work = new HomeWork();
    Image1.ImageUrl = work.GetPictures(0);
    Image2.ImageUrl = work.GetPictures(1);
    Image3.ImageUrl = work.GetPictures(2);
    

    The samples above are to illustrate how C# works.
    It would be inefficient to use it this way in a business application.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 408k
  • Answers 408k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Just call get: HashMap<String, String> map = new HashMap<String, String>();… May 15, 2026 at 6:41 am
  • Editorial Team
    Editorial Team added an answer You need to simply cast the context's connection to a… May 15, 2026 at 6:41 am
  • Editorial Team
    Editorial Team added an answer Create an attached property of type ICommand. When the property… May 15, 2026 at 6:41 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.