Results 1 to 5 of 5

Thread: What is a Variable and Constant in C# ?

  1. #1
    Join Date
    Jul 2006
    Posts
    339

    What is a Variable and Constant in C# ?

    Hi everybody,
    I don't know much things about the C#, since I am new to this programming language. Before this I have completed the C language. I am confused with the variable and constants. Are they same as in C.?? Also do they use the same syntax as in C language.?? I am getting confused when these term comes.!! So explain me what is a Variable and Constant in C# ..? Also provide me with the syntax or the codes in C#.

  2. #2
    Join Date
    Aug 2006
    Posts
    227

    Re: What is a Variable and Constant in C# ?

    If you want to assign the fixed value to a variable, then you can declare it with the const keyword. But one thing you will have to remember that you cannot change the variable across the application's life. Also while doing the Compilation, you must know the value assigned to a constant variable. You will have to declare the variable, before using it. Without declaring you cannot use the variable. To declare a variable you must first choose what data type it is. The variable can be declared according to its type.
    I do to dead flowers what people at morgues do to dead people. Suck all the moisture out, dip them in plastic, paint them up pretty and put them in a nice frame.

  3. #3
    Join Date
    Jul 2006
    Posts
    289

    Re: What is a Variable and Constant in C# ?

    As mentioned above, it is exactly right that you must know the data type of the variable before declaring it. If a number is to be stored then you must use the int data type. After declaring it, you must choose a name for the variable. If you want two or more variables declared in one statement, then you can use the comma to separate them. The following example will explain it more clearly :
    Code:
    int i,j;
    Signatures reduce available bandwidth

  4. #4
    Join Date
    Mar 2008
    Posts
    349

    Re: What is a Variable and Constant in C# ?

    In simple words, you can say that variable declarations require a type, a name and, optionally a value assignment. I have given you an example that declares an integer variable. Just have a look at the example :
    Code:
    int Marks;
    In the above example, I have declared an integer variable called Marks but I haven't initialized it. In the below example, I have declared and initialized a variable using the assignment operator (=);
    Code:
    int Marks = 510;

  5. #5
    Join Date
    Jan 2008
    Posts
    1,521

    Re: What is a Variable and Constant in C# ?

    Just like the variables, constants have a type, a name and a value. The following is an example of declaring the constant in C# :
    Code:
    const int totalmarks = 600;
    The difference between the variables and constants is that you will have to initialize the constant always, but there is no need to initialize variable always. Also the C# provides a number of different integer types based on number size and whether the integers are signed or unsigned.

Similar Threads

  1. Limitations of a variable
    By Wilbur in forum Software Development
    Replies: 3
    Last Post: 15-10-2009, 11:16 AM
  2. Replies: 2
    Last Post: 28-08-2009, 07:51 PM
  3. Replies: 3
    Last Post: 25-04-2009, 11:34 AM
  4. How can I use a variable in an autofilter in VBA
    By Ektaa in forum Software Development
    Replies: 3
    Last Post: 08-04-2009, 08:00 PM
  5. value of a php variable disappears
    By Jasonholt in forum Software Development
    Replies: 3
    Last Post: 04-08-2008, 02:01 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,714,105,076.32892 seconds with 16 queries