Forum General

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Condition false, but code inside the if statement executed

HamittirpanHamittirpan Member ✭✭✭✭
edited August 2019 in General
 using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using GulaylarMenuDesign.Services;
using GulaylarMenuDesign.Tables;
using Newtonsoft.Json;
using Plugin.Settings;
using Rg.Plugins.Popup.Services;
using Xamarin.Forms;

namespace GulaylarMenuDesign.Views
{
public partial class PhonePage : ContentPage
{
    public PhonePage()
    {
        InitializeComponent();
    }
    protected override async void OnAppearing()
    {
        base.OnAppearing();

        var storeString = CrossSettings.Current.GetValueOrDefault("Information", string.Empty);
        if (!string.IsNullOrEmpty(storeString))
        {
            AppCustomer customer = JsonConvert.DeserializeObject<AppCustomer>(storeString);
            Helpers.Settings.GeneralSettings = customer.MobileGsm;
        }
    }
    async void GoUserInfo(Object sender, System.EventArgs e)
    {
        if (Helpers.Settings.GeneralSettings == EntryPhoneNumber.Text)
        {
            await Navigation.PushAsync(new MainPage());
        }
        else
        {
            string validPhone = @"^(05(\d{9}))$";
            Regex rxPhone = new Regex(validPhone);
            var CustomerGsm = EntryPhoneNumber.Text;

            // id Key ile CustomerGsm değişkenini barcode sayfasında kullanıyor
            Application.Current.Properties["id"] = CustomerGsm;
            if (CustomerGsm == null)
            {
                await DisplayAlert("UYARI", "Cep numarası alanı boş geçilemez", "Tamam");
            }
            else if (rxPhone.Match(CustomerGsm).Success)
            {
                ServiceManager manager = new ServiceManager();
                bool result = await manager.GetGsm(CustomerGsm);

                if (result)
                {
                    await PopupNavigation.Instance.PushAsync(new LoginPopUpPage());
                }
                else
                {
                    await Navigation.PushAsync(new UserEntryPage(EntryPhoneNumber.Text));
                }
            }
            else
                await DisplayAlert("UYARI", "Lütfen numaranızı 05xx xxx xx xx formatında tuşlayınız", "Tamam");
        }
    }
  }
}

I've debugged and why is it working even though it turns false?

Helpers.Settings.GeneralSettings == ""
EntryPhoneNumber.Text = "053241231"

Why running if (Helpers.Settings.GeneralSettings == EntryPhoneNumber.Text) ???

Tagged:

Answers

  • ColeXColeX Member, Xamarin Team Xamurai

    Try to use Equals method to compare between strings.

    if (Helpers.Settings.GeneralSettings.Equals( EntryPhoneNumber.Text)) 
    
  • HamittirpanHamittirpan Member ✭✭✭✭

    @ColeX said:
    Try to use Equals method to compare between strings.

    if (Helpers.Settings.GeneralSettings.Equals( EntryPhoneNumber.Text)) 
    

    Hi Cole !
    I think I came across some kind of bug. I tried what you said before, but it didn't work. Although I had cleaned up the project before, it hadn't worked properly. Now I cleaned and run again. Now its work great. Is it a joke ? :neutral:

  • ColeXColeX Member, Xamarin Team Xamurai

    Anyway , it's solved ... :D:D:D

  • tamalausttamalaust Member ✭✭

    @Hamittirpan said:

    @ColeX said:
    Try to use Equals method to compare between strings.

    if (Helpers.Settings.GeneralSettings.Equals( EntryPhoneNumber.Text)) 
    

    Hi Cole !
    I think I came across some kind of bug. I tried what you said before, but it didn't work. Although I had cleaned up the project before, it hadn't worked properly. Now I cleaned and run again. Now its work great. Is it a joke ? :neutral:

    You are right.. I found the same thing... using Equals

Sign In or Register to comment.