Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Local variable
Message
From
10/01/2009 09:22:19
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
10/01/2009 08:12:06
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
Environment versions
Environment:
C# 3.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01372518
Message ID:
01372526
Views:
12
>Hi,
>Does C# support same name in sub method?
>For example, I have declare string abc in ClassA.MethodA(), I also have declared same variable in ClassA.MethodB(). ClassA.MethodA() will call ClassA.Method().
>
>I faced problem that, whenever I have this, program will behave weird, is either take wrong value, or just jump back to calling program without completely execute all necessary code.
>
>Any ideas?
>
>Please advice. Thank you

Each variable are scoped to their bounding blocks (in practice { }). With string abc the 2 variables at different places might be pointing to the same string but since strings are immutable it can't cause a weirdness. IOW once you create a string you can't modify it:

string x = "Hello";
x += " There";

second x is totally a new string.

Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform