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
Solved

VB to C#

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

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Video Player 12 27
Code works but it's slow 28 76
HttpPostedFile 1 30
itextsharp with c# 3 5
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…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

839 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