?
Solved

how to call the variable out of the scope

Posted on 2012-03-12
4
Medium Priority
?
316 Views
Last Modified: 2012-03-12
Hi All,

Am just trying call "paths" in my foreach loop but it keeps on saying its out of scope bcoz i declare the values inside the if loop.

Someone please enlighten me how to call this variable from foreach loop ?

This is the one am calling in my foreach loop "  string[] paths = { Firstpath, SecondPath, ThirdPath };" it depends on the if condition.

Thanks in Advance

            string[] pathsplit = path.ToString().Split('/');
           if(pathsplit[3].contains{"testFile"))
{
            string Firstpath = pathsplit[0] + "/" + pathsplit[1] + "/" + pathsplit[2] + "/" + pathsplit[3] + "/";
            string SecondPath = Firstpath + "/" + pathsplit[4] + "/";
            string ThirdPath = SecondPath + "/" + pathsplit[5] + "/";
            string[] paths = { Firstpath, SecondPath, ThirdPath };
}
else
{
        string Firstpath = pathsplit[0] + "/" + pathsplit[1] + "/" + pathsplit[2] + "/" + pathsplit[3] + "/";
            string SecondPath = Firstpath + "/" + pathsplit[4] + "/";
       string[] paths = { Firstpath, SecondPath };
}
            foreach (string pat in paths)
            {
               bool result= dir.EnsureDirectoryExists(pat);

                if (result==true)
                {
                    //do nothing
                }
                else
                {   //create dir
                    dir.createdir(pat);
                }
            }
            upload(path,filename);

        }
        

Open in new window

0
Comment
Question by:Sha1395
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 21

Assisted Solution

by:Dale Burrell
Dale Burrell earned 2000 total points
ID: 37708680
Before the if statement declare:

string[] paths = null;

Open in new window


then inside the if statement assign it:

paths = { Firstpath, SecondPath, ThirdPath };

Open in new window


and

paths = { Firstpath, SecondPath };

Open in new window

0
 

Author Comment

by:Sha1395
ID: 37712166
thanks dale_burrell,i tried to declared

string[] paths = null; outside the if statement but got the different error  @paths = { Firstpath, SecondPath, ThirdPath }; it throws ";" expected.

Am not sure why it throwing this error
0
 
LVL 21

Accepted Solution

by:
Dale Burrell earned 2000 total points
ID: 37712181
try

paths = new string[] { Firstpath, SecondPath, ThirdPath };

Open in new window


http://msdn.microsoft.com/en-us/library/aa287601(v=vs.71).aspx
0
 

Author Comment

by:Sha1395
ID: 37712189
i got it,it suppose to be declare like

Path= new string[] { Firstpath, SecondPath, ThirdPath }; in the if statement
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month11 days, 17 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question