Solved

VB to C#

Posted on 2011-02-26
5
254 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
  • 2
  • 2
5 Comments
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 200 total points
Comment Utility
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
Comment Utility
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
Comment Utility
That should be valid as it is if that method is in the same page as the btnUpdate handler.
0
 

Author Comment

by:avi7
Comment Utility
Yes, it is... I will try to test it now. Thanks!
0
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 300 total points
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Debug Windows Service program in C# 4 31
Need help with a query 6 53
Duplicate a row 2 28
Image(7) 1 32
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now