---
title: "C# - Access variable Names dynamically"  
description: "C# - Access variable Names dynamically"  
author: "Anonymous User"  
published: 2014-01-31  
updated: 2014-01-31  
canonical: https://www.mindstick.com/forum/1933/c-sharp-access-variable-names-dynamically  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# C# - Access variable Names dynamically

I am automating a [web page](https://www.mindstick.com/forum/718/sql-server-report-alignment-to-center-of-web-page). i have captured and saved the [Links](https://www.mindstick.com/blog/415/css3-links) in a file.

[Link](https://www.mindstick.com/articles/23633/link-builder) Url_0="gmail.com"

Link Url_1="ymail.com"

Link Url_2="hotmail.com"

Link Url_3="outlook.com"

The below statement will [click](https://www.mindstick.com/articles/12423/social-login-magento-2-one-click-to-register-social) on each url.

HomePage.Url_0.Click();//Homepage is the [Class name](https://www.mindstick.com/forum/12871/how-to-get-class-name)

I want to Click these URLs one by one. So I am using a for loop.

for(int i=0;i<3;i++)

{

String url=[String.Format](https://www.mindstick.com/forum/1763/string-format-with-null-values-c-sharp)("Url_{0}",i);

HomePage.url.Click(); //This is throwing me [error](https://yourviews.mindstick.com/view/88527/fixing-quickbooks-error-4120-reinstalling-vs-repairing) (I think that this is not correct way to do.)

[Sleep](https://www.mindstick.com/articles/95806/how-to-get-better-sleep)(2000);

}

How can I proceed here ? Can this be done in any way ? Any help is appreciated.

## Replies

### Reply by Pravesh Singh

Hi Jay,\

You can store all links you want into a Coolection of type: IList<Link> or into an IEnumerable<Link>

IList<Link> myCollection = new List<Link>();

After that, you'll go throuh items in the collection with an

```
foreach(var item in myCollection ) {      //Here implement your logic with click}
```


---

Original Source: https://www.mindstick.com/forum/1933/c-sharp-access-variable-names-dynamically

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
