Results 1 to 4 of 4

Thread: how to create a If-Else statement in C#

  1. #1
    Join Date
    Dec 2010
    Posts
    68

    how to create a If-Else statement in C#

    I’m a tybsc-it student and we are making project in c#, I want to know how to create a if else statement in c#. we are making an application where user need to enter his information in a textbox. I want to give a condition of what to write and what to not write in the textbox, also I don’t want to allow user to left any blank space in a textbox but I don’t know how to use a if else statement in coding. Please give me the coding and explain me how to use if else statement in my program, please help me.

  2. #2
    Join Date
    Nov 2008
    Posts
    1,221

    Re: how to create a If-Else statement in C#

    Usually in c# the code written is executed from first to last but by using if else statement you can execute any statement at any particular time. If is a keyword in c# which is used to declare a condition. You can specify a statement which you want to execute in if statement. You can give the condition if this not happen do that. The condition which you want to test first is written in if block. The condition under if block is tested first and if the condition is true then it does’nt goes in the else block if condition is false then it goes in the else block and execute the statement inside the else block. You can use if else block for testing the condition in your program.

  3. #3
    Join Date
    Nov 2008
    Posts
    1,022

    Re: how to create a If-Else statement in C#

    You can use if else statement in a situation where you don’t know what will be the condition and you’re not sure about the data to be enter into textbox. Usually the if else statement is uses mostly at the time of creating a textbox where we don’t know what data user will enter in to the textbox. For example if you have created a textbox for putting a number into that and by mistake user has entered alphabet in that and submitted that form, then it will store in a database and our database will become inconsistent. So, we use if else statement to give a condition

  4. #4
    Join Date
    May 2008
    Posts
    860

    Re: how to create a If-Else statement in C#

    If you’re a tybsc-it student then you should know the if else statement it is already there in java and c++. For making project you should know this concept. If else statement is use for any condition. If you think there will be more then one condition at any situation then you can give if else condition. As you have said you’re making a application, then you can give condition to the user of what should enter in a textbox and what should not enter in a textbox. you can see the following example to understand the structure of if else statement:
    If ( condition is = true ) then execute the following statement, if false then execute else statement
    { statement…
    }
    Else
    { statement…
    }

Similar Threads

  1. Replies: 1
    Last Post: 16-08-2010, 02:03 PM
  2. How to use Else and Else If Statement in PHP?
    By Orton in forum Software Development
    Replies: 5
    Last Post: 05-03-2010, 06:49 AM
  3. How to use If statement in PHP?
    By Deabelos in forum Software Development
    Replies: 4
    Last Post: 09-02-2010, 06:14 AM
  4. Want to create if statement in SQL
    By Reckon in forum Software Development
    Replies: 3
    Last Post: 29-07-2009, 01:00 PM
  5. Replies: 4
    Last Post: 25-02-2009, 08:52 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,750,307,176.75492 seconds with 16 queries