Solved

VB to C#

Posted on 2011-02-26
5
255 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
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 62

Accepted Solution

by:
Fernando Soto earned 300 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

867 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

22 Experts available now in Live!

Get 1:1 Help Now