IT Community - Software Programming, Web Development and Technical Support

Restricting the scope of a method

This is a discussion on Restricting the scope of a method within the C# Programming forums, part of the Software Development category; Is it possible to restrict the scope of a field/method of a class to the classes in the same ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C# Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 09-04-2007, 01:17 PM
Sathish Kumar Sathish Kumar is offline
D-Web Analyst
 
Join Date: Feb 2007
Posts: 304
Sathish Kumar is on a distinguished road
Exclamation Restricting the scope of a method

Is it possible to restrict the scope of a field/method of a class to the classes in the same namespace?
__________________
Sathish Kumar.R
Knowledge is meant to SHARE
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 09-04-2007, 10:33 PM
smani smani is offline
D-Web Programmer
 
Join Date: Aug 2007
Posts: 56
smani is on a distinguished road
Default Re: Restricting the scope of a method

hi,
yes, it is possible to restrict by using "private-access specifier"

eg:

namespace Test
{
public partial class ClassTest
{
public void callme()
{
}

private void callme1()
{
}
}
}

in another class in the same namespace
using Test
namespace Test
{
public partial class ClassTest1
{
public void Tocall()
{
ClassTest obj=new ClassTest();
//here you can access the public function callme() using this object,
// but you can't call callme1()
}
}
}


Regards
Manivannan.s
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-05-2007, 08:03 AM
Mramesh Mramesh is offline
D-Web Sr.Programmer
 
Join Date: Sep 2007
Location: Chennai
Posts: 106
Mramesh is on a distinguished road
Send a message via MSN to Mramesh
Thumbs up Re: Restricting the scope of a method

Hi Mani and Sathish,
There is no way to restrict to a namespace. Namespaces are never units of protection. But if you’re using assemblies, you can use the ‘internal’ access modifier to restrict access to only within the assembly.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 09-05-2007, 08:08 AM
Sathish Kumar Sathish Kumar is offline
D-Web Analyst
 
Join Date: Feb 2007
Posts: 304
Sathish Kumar is on a distinguished road
Thumbs up Re: Restricting the scope of a method

Hi,
Yes.internal access modifier can restrict the access within the assembly.Thanks for your help.
__________________
Sathish Kumar.R
Knowledge is meant to SHARE
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Scope of testing?? ammulu Software Testing 3 01-10-2008 11:27 AM
Scope Trouble while calling Functions aramesh Flash Actionscript Programming 1 12-14-2007 05:29 AM
scope variable itbarota HTML, CSS and Javascript Coding Techniques 1 11-13-2007 12:29 AM
What is Variable Scope in PHP? itbarota PHP Programming 1 10-25-2007 03:23 AM
Transaction Scope in DotNet using C#. S.Vinothkumar C# Programming 52 09-22-2007 01:15 AM


All times are GMT -7. The time now is 11:29 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0