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

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...

C# Programming Structure | WaoFamHub

C# Programming Structure. The lists of elements that are commonly used in a C# program are: Library invoked by the keyword "using". Declaring namespace using the "namespace" keyword. Declaring a class using the keyword "class". Class members and attributes. The Main() method. Other statements and expressions. Writing comments for user understanding and non-executable statements. Let's look into various parts of the above C# program. /* Comments */ /* Print, some string in C# */, is the comment statement that does not get executed by the compiler and is used for code readers or programmers' understanding. using Here, using keyword is employed for fetching all the associated methods that are within the System namespace. Any C# program can have multiple using statements. namespace Next statement is used for declaring a namespace, which is a collection of classes under a single unit; here "printHelloCsharp". Class Next, you have declared a cl...