Private class function

Private class function

Ed__Jobe
Mentor Mentor
505 Views
4 Replies
Message 1 of 5

Private class function

Ed__Jobe
Mentor
Mentor

I want to have a function in a form that doesn't have a return type, it just sets some form controls. Something like the following.

private void SetList { }

However, I get error CS0547 that a property or indexer cannot have a void type. The method doesn't need a return type or any arguments. The problem is that VS thinks it's a property.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Accepted solutions (1)
506 Views
4 Replies
Replies (4)
Message 2 of 5

kerry_w_brown
Advisor
Advisor

 

How about

 

private void SetList()
{
   //here be dragons
}

 

 

Regards,


// Called Kerry or kdub in my other life.

Everything will work just as you expect it to, unless your expectations are incorrect. ~ kdub
Sometimes the question is more important than the answer. ~ kdub

NZST UTC+12

class keyThumper<T> : Lazy<T>;      another  Swamper

0 Likes
Message 3 of 5

Ed__Jobe
Mentor
Mentor

I think that is the same as what I have. I also think that the problem stems from the fact that the method exists in a form's partial class. The syntax you showed is fine in a regular class. That's the only difference I can see.


    public partial class frmGetFilesFromFolder : Form
    {
        public frmGetFilesFromFolder()
        {
            InitializeComponent();
        }
        public void SetList()
        {
        }
    }

 

I went ahead and abandoned this form, though. However, I would like to still understand the problem.

 

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 4 of 5

kerry_w_brown
Advisor
Advisor
Accepted solution

Hi Ed,
In C# a Method requires parentheses.

Without parentheses the compiler thinks the declaration is a property or indexer.

The OP is absent parentheses.


Interesting point about partial classes but I'd need to test before commentng on that unusual case.

 

Regards,


// Called Kerry or kdub in my other life.

Everything will work just as you expect it to, unless your expectations are incorrect. ~ kdub
Sometimes the question is more important than the answer. ~ kdub

NZST UTC+12

class keyThumper<T> : Lazy<T>;      another  Swamper

0 Likes
Message 5 of 5

Ed__Jobe
Mentor
Mentor

Duh! I didn't catch that. Been away from programming in C# for too long.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes