Solved

VB to C#

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
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.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

785 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