Skip to main content

Variables In C# | WaoFamHub



What Are Variables In C#.

C# Programming Language


Variables are specific names given to locations in the memory for storing and dealing with data. The values of a variable can be changed or reused as many times as possible. Every variable name has a specific type that resolves the size and layout of memory the variable will hold as well as the range of values that variable within your program can hold. Also, programmers can determine which variables can be applied to which type of operation.

Types Of C# Variables.

The basic types of variables that can be formed in a C# program are:

Integral

typessbyte, byte, short, ushort, int, uint, long, ulong, and char

Floating-point types

float and double

Decimal types

decimal

Boolean types

true or false values, as assigned

Nullable types

Nullable data types

Define Variables In C#.

For implementing variables in a C# program, you have to define them before use. To do this, the syntax is:

<data_type> <variable_names>;

Here data_types will be a valid data type (such as char, int, float, double, or any other user-defined data type) of C#, and the variable_names will be the set of variable names which are valid C# identifiers separated by commas.

Example

char s, chrr;

int a, b, c;

float pi, sal;

double aadharno;

Common Examples.

char ch = 'g';

int xy = 6, roll = 42;

byte b = 22;

double pi = 3.14159;

float salary = 20000.0f;

Accepting Values In Program.

There is a particular function of the Console class that provides the function Readline() to take input from the user for storing them in a variable, which is ultimately a named memory location.

Let us see how to use this function name with any variable to fetch (using the keyboard) and assign values to that variable:

Example

double sal;
sal = Convert.ToDouble(Console.ReadLine());

In the above code snippet, the first line will declare a variable as a double type. The second line will first execute the right side, which will wait for the user to input any number and will convert the input values to double using the Convert.ToDouble() and will finally assign that value to the 'sal' variable using the assignment operator (=).


Comments

Post a Comment

Popular posts from this blog

Hello World Example In C Programming | WaoFamHub

Hello World Example A C program basically consists of the following parts − Preprocessor Commands Functions Variables Statements & Expressions Comments Let us look at a simple code that would print the words "Hello World" − INPUT #include <stdio.h> void main {    /* my first program in C */    printf("Hello, World! \n");    getch; } Let us take a look at the various parts of the above program − The first line of the program #include <stdio.h> is a preprocessor command, which tells a C compiler to include stdio.h file before going to actual compilation. The next line int main() is the main function where the program execution begins. The next line /*...*/ will be ignored by the compiler and it has been put to add additional comments in the program. So such lines are called comments in the program. The next line printf(...) is another function available in C which causes the message "Hello, World!" to be displayed on the screen. The next line...

Why Software Engineering is Popular? | WaoFamHub

Why Software Engineering is Popular? Here are important reasons behind the popularity of software engineering: Large software – In our real life, it is quite more comfortable to build a wall than a house or building. In the same manner, as the size of the software becomes large, software engineering helps you to build software. Scalability - If the software development process were based on scientific and engineering concepts, it is easier to re-create new software to scale an existing one. Adaptability : Whenever the software process was based on scientific and engineering, it is easy to re-create new software with the help of software engineering. Cost - Hardware industry has shown its skills and huge manufacturing has lower the cost of the computer and electronic hardware. Dynamic Nature - Always growing and adapting nature of the software. It depends on the environment in which the user works. Quality Management : Offers better method of software development to provide quality so...

Bresenham’s Line Drawing Algorithm Program In C | WaoFamHub

Bresenham’s Line Drawing Algorithm Program In C INPUT #include<stdio.h> #include<graphics.h> void drawline(int x0, int y0, int x1, int y1) { int dx, dy, p, x, y; dx=x1-x0; dy=y1-y0; x=x0; y=y0; p=2*dy-dx; while(x<x1) { if(p>=0) { putpixel(x,y,7); y=y+1; p=p+2*dy-2*dx; } else { putpixel(x,y,7); p=p+2*dy; } x=x+1; } } int main() { int gdriver=DETECT, gmode, error, x0, y0, x1, y1; initgraph(&gdriver, &gmode, "c:\\turboc3\\bgi"); printf("Enter co-ordinates of first point: "); scanf("%d%d", &x0, &y0); printf("Enter co-ordinates of second point: "); scanf("%d%d", &x1, &y1); drawline(x0, y0, x1, y1); getch(); } OUTPUT

Draw A Simple Hut On The Screen Program In C | WaoFamHub

A Simple Hut On The Screen INPUT #include<graphics.h> #include<conio.h> int main(){ int gd = DETECT,gm; initgraph(&gd, &gm, "C:\\TURBOC3\\BGI"); setcolor(WHITE); rectangle(150,180,250,300); rectangle(250,180,420,300); rectangle(180,250,220,300); line(200,100,150,180); line(200,100,250,180); line(200,100,370,100); line(370,100,420,180); setfillstyle(SOLID_FILL, BROWN); floodfill(152, 182, WHITE); floodfill(252, 182, WHITE); setfillstyle(SLASH_FILL, BLUE); floodfill(182, 252, WHITE); setfillstyle(HATCH_FILL, GREEN); floodfill(200, 105, WHITE); floodfill(210, 105, WHITE); getch(); closegraph(); return 0; } OUTPUT

AMP Website VS Normal Website | WaoFamHub

AMP Site VS Normal Site What Is AMP Site? AMP (originally an acronym for Accelerated Mobile Pages) is an open source HTML framework developed by the AMP Open Source Project. It was originally created by Google as a competitor to Facebook Instant Articles and Apple News. AMP is optimised for mobile web browsing and intended to help webpages load faster. What Is Website? A website (also written as web site) is a collection of web pages and related content that is identified by a common domain name and published on at least one web server. ... Websites are typically dedicated to a particular topic or purpose, such as news, education, commerce, entertainment, or social networking. Whay AMP Site Load Fast? AMP-built web pages have a lightning bolt indicator in the search result. This is what an AMP page looks compared to a normal web page: The reason why AMP pages load instantly is because AMP restricts HTML/CSS and JavaScript, allowing faster rendering of mobile web pages. How To Make AMP ...

What Is Google Schemas? And Types | WaoFamHub

Google Schema What is Google Schema? (V1) Schema.org (often called Schema) is a semantic vocabulary of tags (or microdata) that you can add to your HTML to improve the way search engines read and represent your page in SERPs. What Is Google Schemas ? (V2) Website Schemas are essentially words or tags in a “shared vocabulary” that can be used by your on-line marketing company (like us!) to talk to search engines like Google & Bing to provide refined searches. What Is Google Schemas? (V3) Schema markup, also known as structured data, is the language of search engines, using a unique semantic vocabulary. It is code used to more clearly provide information to search engines in order to understand your content. In turn, this helps provide users with better, more accurate information in the rich snippets that are displayed beneath the page title. What is schema and why is it important? Schema is powerful and important. By being able to implement and use this information. You'll not o...

What Is C Programming? | Why To Learn C Programming | WaoFamHub

What Is C Programming C programming is a general-purpose, procedural, imperative computer programming language developed in 1972 by Dennis M. Ritchie at the Bell Telephone Laboratories to develop the UNIX operating system. C is the most widely used computer language. It keeps fluctuating at number one scale of popularity along with Java programming language, which is also equally popular and most widely used among modern software programmers. Why to Learn C Programming? C programming language is a MUST for students and working professionals to become a great Software Engineer specially when they are working in Software Development Domain. I will list down some of the key advantages of learning C Programming: Easy to learn Structured language It produces efficient programs It can handle low-level activities It can be compiled on a variety of computer platforms Facts about C C was invented to write an operating system called UNIX. C is a successor of B language which was introduced aroun...