?
Solved

VB to C#

Posted on 2011-02-26
5
Medium Priority
?
260 Views
Last Modified: 2012-05-11
Hi,
Could someone please take a look at this and tell me why this might not work… I am trying to pass a bool value true or false in order to do some additional inserts or updates when user clicks on Update button.
The error is: Cannot assign to 'CustAccount' because it is a 'method group'      

Thanks!
 
private bool CustAccount()
  {
     if (Convert.ToInt32(lblTotal.Text) > 30)
     {
      if (txtPrice.Text != "")
      {
        DisplayAccountInfo();
        CustAccount = false;  <-- error
       }
       else
       {
         if (lblRec.Text != "")
       {
        //some code          
             }
  CustAccount = true; <--error
}
         }
    }

protected void btnUpdate_Click(object sender, EventArgs e)
    {
        if (CustAccount() == false){
        }    
        else{
0
Comment
Question by:avi7
[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
5 Comments
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 800 total points
ID: 34988848
That should say:
return true;

Open in new window

The whole "assigning the return value to the method name" thing is a VB specific convention. What you are actually doing is returning a value from the method, which in C# uses the "return" keyword.
0
 

Author Comment

by:avi7
ID: 34988905
OK... thanks!
But how should I modify this part of the code to make it to work:

protected void btnUpdate_Click(object sender, EventArgs e)
    {
        if (CustAccount() == false){  <---------------
        }    
        else{
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34988908
That should be valid as it is if that method is in the same page as the btnUpdate handler.
0
 

Author Comment

by:avi7
ID: 34988913
Yes, it is... I will try to test it now. Thanks!
0
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 1200 total points
ID: 34990043
Hi avi7;

In C# you need to use the return key word unlike in VB where you can use the method name.

private bool CustAccount()
{
    if (Convert.ToInt32(lblTotal.Text) > 30)
    {
        if (txtPrice.Text != "")
        {
          DisplayAccountInfo();
          return false;                                     // Use return key word
        }
        else
        {
           if (lblRec.Text != "")
           {
               //some code          
           }
           
     // ...
     return true;                     // Use return key word




protected void btnUpdate_Click(object sender, EventArgs e)
{
    if (CustAccount() == false)
    {
    
    }    
    else{

Open in new window


Fernando
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
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

764 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