What Use Cases Exist For Non-static Private Or Protected Events

Sep 25, 2009

What purpose do protected or private (non-static) events in .NET really serve?It seems like any private or protected event is more easily handled via a virtual method. I can (somewhat) see the need for this in static events, but not for normal events. Have you had a use case before that clearly demonstrates a need or advantage for a non-static protected or private event?

View 5 Replies


ADVERTISEMENT

C# - When Should Use Public / Private / Static Methods

Apr 27, 2009

I'm new to C#.Till this moment I used to make every global variable - public static.All my methods are public static so I can access them from other classes. I read on SO that the less public static methods I have,the better.So I rewrote my applications by putting all the code in one class - the form class.Now all my methods are private and there's no static method.

My question: What should I do,keeping everything in the form class is dump in my opinion. When should I use public,when private and when static private/public? I get the public methods as a 'cons' ,because they can be decompiled,but I doubt that.My public methods can be decompiled too.What is so 'private' in a private method? EDIT: I'm not asking how to prevent my program to be decompiled,I'm asking whether I should use static,private and public.And also : Is there are problem in putting all the code in the form class so I dont have to use public methods?

View 6 Replies

Private Fields Have To Be Declared Static?

Aug 18, 2010

I am a vb.net programmer switching to C#.I have the following code for a console application (targeting NET20)

using System;
using System.IO;
using System.Data;[code]....

This is giving a compile error in the if clause of InitVars for the _dbName variable:

Error 1 An object reference is required for the non-static field, method, or property 'eScoreSwapper.Program._dbName' C:UsersSethSDocumentseScoreVersionsTrunkdotNeteScoreSwappereScoreSwapperProgram.cs 26 38 eScoreSwapper

C# does not allow you to reference private class fields unless they are declared static?

View 7 Replies

Private Or Protected Set For A MustOverride Property?

Jul 24, 2010

I'd like to have a Private or Protected "Setter" for a property that also happens to be an abstract (MustOverride). I'm porting some code from C# to VB and in C# this is pretty straight forward. In VB not so much (for me anyway).

Some code...

In C#...
public abstract class BaseClassWithAnAbstractProperty
{
public abstract int AnAbstractIntegerProperty { get; protected set; }
}

[Code]....

The issue seems to be the inability to flesh-out the Get/Set specifics in the declaration.

View 2 Replies

Private Vs Protected - Button Click Event Is Created In ASP.NET ?

Feb 22, 2012

In ASP.NET using VB.NET, you can define the wired up button click event (to an ASP.NET server control) in 2 different ways (for the purpose of this conversation - manually wiring up via button property not in question here):

Double click on the button in the designer which produces an event in the code behind with a Protected method.In the code behind, select the button from the list of controls, and then select it's 'Click' event. This produces a Private method.I understand the difference between Private and Protected; why based on how the wired up event is autocreated it generates a different Access Level on the method?

View 1 Replies

C# - Invoking Private / Protected Methods Via Reflection From The Same Object Instance (or Base)

Jan 5, 2012

Is it possible to call a protected method via reflection. I am using this:

Me.GetType.InvokeMember(Stages(CurrentStage),
Reflection.BindingFlags.InvokeMethod,
Nothing,
Me,
Nothing)

Which always calls a method with no params or return. The idea is that the user of my object (transactional processing of business logic) inherits the base class adds in a load of private methods to fire. They then add these method names to a list in the order they would like them fired and the code above will take care of firing them.

It works fine with public methods but not with private or protected methods in the same class (Protected because I have some 'standard' pre built methods to add to the base class). Realistically I could make the methods public and be done with it but my inner nerd wont allow me to do so...

I am assuming this is a security feature. Is there a way to get around this or does anyone have any suggestions on how to proceed but keep my tasty, tasty visibility modifiers in tact?

(NOTE: ITS IN VB.NET but a C# Answer is fine if that is what you are comfortable with).

View 3 Replies

VS 2008 - Difference Between Public, Private, Protected When Declaring Functions And Subs?

Jul 19, 2009

i have have a few questions about the syntax of the lan.:

1) What is the 'Get' statement and when do you use it?

2) Whats the difference between public, private, protected etc... when declaring functions and subs.

3) When would you use the overrides property?

View 4 Replies

Shared (Static) Classes With Events In C#

Mar 27, 2010

[code]Now how do i do this in c#. I know there is not handles clause in c# so i need some function that is called and assign the event handlers there. However since its a shared class there is no constructor i must put it somewhere outside of a function.

View 2 Replies

Reflection - Find From A Property Info Object If That Property Has A Non Public (Private / Protected) Setter?

Aug 27, 2009

I searched on the forum / Internet for the solution how a PropetryInfo object (of a Public property) can reveal if it has a Private Protected Setter ... it was all in vain .... all help I found was about how to "Set" value of a public property having a Private Setter.I would like to know if I have a PropertyInfo object of a public property, how would I know if its Setter is Non Public?

I tried, in a exception handling block, where I did a GetValue of the PropertyInfo object and then called SetValue by setting the same value back... but to my surprise it worked well and didn error out.

[Code]...

View 1 Replies

VS 2010 Setting Control Events To A Control That Doesn't Exist Yet

Jul 23, 2011

I am looking how to set events to a webrowser which is being created by the following:

[Code]...

View 1 Replies

Error : Protected ReadOnly Property InnerChannel As TChannel' Is Not Accessible In This Context Because It Is 'Protected'

Apr 12, 2010

I am having a Friend Class InterceptingChannelBase class.It has a property as below:

Protected ReadOnly Property InnerChannel() As TChannel
Get
Return Me.innerChannelT

[code]....

This class is being inherited by (Friend Class InterceptingInputChannel) class which in turn contains another (Private Class TryReceiveAsyncResult) class.The property above is being used in this private class as below:

Public Sub New(ByVal channel As InterceptingInputChannel(Of TInputChannel), ByVal timeout As TimeSpan, ByVal callback As AsyncCallback, ByVal state As Object)
MyBase.New(channel, callback, state)

[code]....

I am getting the error on the above underlined statement saying that Protected Readonly Property InnerChannel is not accessible in this context because it is declared asa Protected.As far as i think,if i declare a property in class as 'Protected' then if this class is inherited by 'another' class then i can use this property and it should not throw an error.

View 3 Replies

Can't Make Difference Between Public Class And Private Class And Friend And Protected Friend Class

May 15, 2009

I can't make difference between public class and private class and friend and protected friend class.

View 1 Replies

Protected Error In Compile Time, When No Protected Class Is Used?

Nov 10, 2011

Dim box As MultiTextBox = New MultiTextBox

Dim i As Integer
for i = 1 to 3 Step 1
lengthWidthHeight = MultiTextBox.GetItemValues()
Next i

This excerpt of code is using the NXOpen API. In the NXOpen API, the MultiTextBox class is public. However, when I compile the code I get the message:

'NXOpen.UIStyler.MultiTextBox.Protected Sub New(ptr As System.IntPtr)' is not accessible >in this context because it is 'Protected'

My question is, how am I getting an error about protected scope? Could it also be that the API documentation is incorrect?

View 2 Replies

Create An Application Autoupdate - Check In A Webserver If Exist New Version,if Exist The Software Run Update

Dec 21, 2010

I try to find online any example for create an application autoupdate.

When I run my application it check in a webserver if exist new version,if exist the software run update.

View 8 Replies

VS 2008 Sharing Variables - Private Sub Could Use The Variable Created On Private Sub

Jul 23, 2010

if for example i have two private sub I declared a local variable on private sub a... is there a way that private sub b could use the variable created on private sub a? Im asking because im in a problem in my app were using global variable is not an option to make the long story short

View 5 Replies

Namespace Of "system.runtime.caching" Does Not Exist But In Object Explorer And Microsof Exist?

Nov 25, 2010

namespace of "system.runtime.caching" does not exist but in object explorer and microsof exist.i use microsoft visual studio 2010 and .net framework 4.0.i also cant use this name space(System.IO.MemoryMappedFiles & System.Runtime.Caching.MemoryCache)

any body know what is the problem. i want my program after doing something (opening a file or any thing that can do something my program use more memory.)use memory like startup run.

View 2 Replies

Rich Text Box That Does Not Exist Yet In A Tab That Does Not Exist?

Jan 16, 2011

Here's my code:

Option Infer Off
Option Explicit On
Option Strict On
Public Class Form1

Public Sub NewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewToolStripMenuItem.Click

[Code]...

View 11 Replies

What’s The Difference Between Private Sub And Private Function

Dec 14, 2011

I am completely lost on procedures. Whats the difference bewteen Private sub and private function?

View 1 Replies

How To Avoid If ... Else And Switch Cases

Aug 3, 2010

I have been programming for alot of time. Generally i program in some languages like PHP, ASP.net, Java, JavaScript and others. In all languages i have to use alot of if else statments . Like if value= 10 then ... if i review my code then i find alot of if conditions. So i would like to minimise them but how not sure. one point was using classes somewhat minimised but still they are more... like task, cat, sec and type:

[Code]...

View 9 Replies

Use Switch Cases In Calculator?

Mar 7, 2011

Private Sub cmdCalculate_Click()
Dim Run As Double
Dim Rise As Double

[Code]....

View 2 Replies

Using Cases And Validating Input?

May 18, 2009

I am trying to calculate from a case, and it does not seem to work, and I also need to validate when no input is entered and the person presses the calculate button. my code is a follows

Public Class Question2
Dim intSal, intCount As Single
Dim intPiece, intRates, intPay As Long

[code].....

View 2 Replies

Button That Determine If File Exist And If That File Exist Then Show A Messagebox?

Sep 16, 2009

I have Requests for VB(2005) very very important for my selly project!i need a button that determine if file exist and if that file exist then show a messagebox!and if not show messagebox!.

View 2 Replies

Code To Check Database Exist In SQL And Message Box Show Database Exist Yes/NO?

Apr 23, 2012

I want a Code to check Database exist in SQL and Message Box Show Database Exist Yes/NO?

View 1 Replies

C# - Use-cases For IsLittleEndian In BitConverter Class?

Jun 20, 2011

I was so happy when I discovered IsLittleEndian field in BitConverter. I thought of course it should be there and I should be able to specify whatever endian I like. Well, my happiness didn't last long. Spent some time till found out that there is no way to set the field.The field is readonly, and it is only set to true in static constructor:

[Code]...

My question is: how come there is very useful piece of code that is already implemented and sitting there in the FCL, but there is no way to use it (unless you start messing with reflection of course)? Is it just because some developers didn't meet the deadline and left the job half-done? Even if so, why the code is not available, but the field is?I hope there is a good reason for this.

I want to make myself clear. I don't need a solution on how to handle big-endian values. I do have a solution. The solution is actually shown in my question.

View 6 Replies

Hide DataGridViewCheckBox Cell In Some Cases?

Jul 15, 2010

I have a DataGridView and one column has DataGridViewCheckBoxColumn type .The datagrid loads from selected items of a listbox.I need to hide Check box cell in this grid according to the item. It means some items should not have checkbox in that cell(I have the list of those items which should not have checkbox in that cell).

View 3 Replies

Query Include All Fields In Some Cases But Not Others?

Oct 15, 2010

This LINQ to SQL query From g In Db.Context.Current.Groups Select g.GroupID

generates this SQL:

SELECT [t0].[GroupID] FROM [dbo].[Groups] AS [t0]But this query From g In Db.Context.Current.Groups
Select g.GroupID, g.MemberCount

[Code]...

I very much want to select only the fields I need. How can I persuade LINQ to SQL not to select all columns?

View 1 Replies

Retaining All Selected Items In All Cases

Jan 25, 2009

I can't remember very well the instances where my selected items has disappeared as if I did a "Reset ToolBox", the last time I remember was when I installed the Service Pack early this year. But last year I think it has been reset frequently and I find it bothersome to reselect all those items again and again.Is there any configuration that I could set so that my selected items are safeguarded, that is they won't be removed no matter what?

View 4 Replies

Select Cases From External Location

Jun 21, 2012

I'd like to select my cases from an external location.[code]I want my users, when they click a button, to download a file from my Dropbox(a .txt file). Then, the file will read all of the code, and add it to the code..So for example if in the .txt it was something like.[code]

View 3 Replies

VS 2008 Difference Between Cases And If Statements?

Jun 15, 2009

what exactly the difference between using cases and if statements are.

View 4 Replies

Case Block - Get The Program To Drop Into The Different Cases

Nov 24, 2011

I am having trouble figuring out what I need to do in order to get the program to drop into the different cases. I am suppose to be doing a case block for this assignment. I believe everything else is good but it always outputs the first case and doesn't progress down depending on the inputs. I tried to number them case 1, case 2, etc.. Here is the code

[Code]...

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved