0% found this document useful (0 votes)
8 views15 pages

C# Microsoft Study

Uploaded by

Himanshu Goel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views15 pages

C# Microsoft Study

Uploaded by

Himanshu Goel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
You are on page 1/ 15

C# Beginner with certificate

https://www.classcentral.com/report/best-free-c-sharp-courses/#anchor-2
wrong

Diff

Variable name rules


and conventions
C# is a case-sensitive language, meaning that the C# compiler considers the words console and Console as
different as the words cat and dog.

A programming language's job is to allow a human to write instructions in a human-readable and


understandable way. The instructions you write in a programming language are called "source code", or
just "code".
Console.WriteLine('Hello World!');

Console.WriteLine() and Console.Write()

What is complier?

Console.WriteLine("Hello World!");

The WriteLine() part is called a method. You can always spot a method because it has a set of parenthesis
after it.
Operator
The parentheses are known as the method invocation operator.
There is also a dot, or period, that separates the class name Console and the method name WriteLine(). The
period is the member access operator.
the semicolon is the end of statement operator.
Capitalize Console, Write, and Line
https://learn.microsoft.com/
Literal
If we only wanted a single alphanumeric character printed to screen, we could create a char literal by
surrounding one alphanumeric character in single-quotes.
If you want to print a numeric whole number (no fractions) value to Output, you can use an int literal.

If we wanted to print a number that includes values after the decimal point, we could use a decimal literal.
Without the literal suffix m, the decimal number in the previous example will be treated as type double by
the compiler and the output will be 12.3.
Variable
Variable names can contain alphanumeric characters and the underscore character. Special characters
like the hash symbol # (also known as the number symbol or pound symbol) or dollar symbol $ are not
allowed.
Variable names must begin with an alphabetical letter or an underscore, not a number. Developers use
the underscore for a special purpose, so try to not use that for now.
Variable names must not be a C# keyword. For example, you cannot use the following variable
declarations: decimal decimal; or string string;.
Variable names are case-sensitive, meaning that string Value; and string value; are two different
variables.
Variable names should use camel case, which is a style of writing that uses a lower-case letter at the
beginning of the first word and an upper-case letter at the beginning of each subsequent word. For
example, string thisIsCamelCase;.
Variable names shouldn't include the data type of the variable. You might see some advice to use a style
like string strValue;. That advice is no longer current.
Before you can use a variable, you have to declare it.
You must assign (set) a value to a variable before you can retrieve (get) a value from a variable.
string Formatting
What if you need to use the backslash for other purposes, like to display a file path?
(1,22): error CS1009: Unrecognized escape sequence
Verbatim String Literal
A verbatim string literal will keep all whitespace and characters without the need to escape the backslash.
To create a verbatim string, use the @ directive before the literal string. Two consecutive double-quote
characters ("") are printed as a single double-quote character (") in the output string.
Console.WriteLine(@" c:\source\repos (""this is where your code goes"")");
Unicode Escape Characters
You can also add encoded characters in literal strings using the \u escape sequence, then a four-character
code representing some character in Unicode (UTF-16).
Use character escape sequences when you need to insert a special character into a literal string, like a
tab \t, new line \n, or a double quotation mark \".
Use an escape character for the backslash \\ when you need to use a backslash in all other scenarios.
Use the @ directive to create a verbatim string literal that keeps all whitespace formatting and backslash
characters in a string.
Use the \u plus a four-character code to represent Unicode characters (UTF-16) in a string.
String Concate
To concatenate two strings together, you'll use the string concatenation operator, which is the plus symbol +.
String Interpolation

String interpolation combines multiple values into a single literal string by using a "template" and one or
more interpolation expressions. An interpolation expression is a variable surrounded by an opening and
closing curly brace symbol { }. The literal string becomes a template when it's prefixed by the $ character.

Combine verbatim literals and string interpolation


The user console doesn't support the unicode character when ? Output
Simple Addition and Implicit Data Conversion
The reuse of one symbol for multiple purposes is sometimes called "overloading the operator," and
happens frequently in C#.
Namespace
A namespace prevents naming collisions between class names in the .NET Class Library.
Stateful versus stateless methods
For example, the Console.WriteLine() method doesn't rely on any values stored in memory. It performs its
function and finishes without impacting the state of the application in any way.

Other methods, however, must have access to the state of the application to work properly. In other
words, stateful methods are built in such a way that they rely on values stored in memory by previous
lines of code that have already executed, or they modify the state of the application by updating values or
storing new values in memory. They're also known as instance methods.

Stateful (instance) methods keep track of their state in fields, which are variables defined on the class.
Each new instance of the class gets its own copy of those fields in which to store state.

A single class can support both stateful and stateless methods. However, when you need to call stateful
methods, you must first create an instance of the class so that the method can access state.
Stateful (instance) methods keep track of their state in fields, which are variables defined on the class.
Each new instance of the class gets its own copy of those fields in which to store state.

A single class can support both stateful and stateless methods. However, when you need to call stateful
methods, you must first create an instance of the class so that the method can access state.
Creating an instance of a class
Random dice = new Random();
The new operator does several important things:

It first requests an address in the computer's memory large enough to store a new object based on
the Random class.
It creates the new object and stores it at the memory address.
It returns the memory address so that it can be saved in the dice variable.
Overloaded methods
An overloaded method is defined with multiple method signatures. Overloaded methods provide different
ways to call the method or provide different types of data.
(1,19): error CS1012: Too many characters in character literal
the first technique used Console.WriteLine(). At the end of the line, it added a line
feed similar to how to create a new line of text by pressing Enter or Return.
Compilers bridge these two worlds by translating your human-readable
instructions into a computer-understandable set of instructions.
When the phrase is surrounded by double-quotation marks in your C# code, it's
called a literal string.

The WriteLine() method's job is to write a line of data to the output window.

Console.WriteLine('b');

To create a decimal literal, append the letter m after the number. In this context,
the m is called a literal suffix. The literal suffix tells the compiler you wish to work
with a value of type decimal.
Console.WriteLine("c:\source\repos");

c:\source\repos ("this is where your code goes")

us symbol +.

string message = greeting + " " + firstName + "!";


string message = $"{greeting} {firstName}!";
So, the next call
to Console.Write() prints an additional
message to the same line.
1
2
3
4

5
6
7
https://learn.microsoft.com/

How to declare a variable?


Variable names can contain alphanumeric characters and the underscore character.
Special characters like the hash symbol # (also known as the number symbol or pound symbol) or dollar symbol
Variable names must not be a C# keyword. Example- decimal decimal; or string string;.
Variable names are case-sensitive, meaning that string Value; and string value; are two different variables.
Variable names should use camel case, which is a style of writing that uses a lower-case letter at the beginning
word. For example, string thisIsCamelCase;.
Variable names should be descriptive and meaningful in your application.
Variable names shouldn't include the data type of the variable. You might see some advice to use a style like st
Examples:
char userOption; int gameScore; decimal particlesPerMillion; bool processedCustomer;

String interpolation provides an improvement over string concatenation by reducing the number of characters required in som

Variable name rules


Variable name rules

Variable names can contain alphanumeric characters and the underscore character. Special characters like the
Variable names must begin with an alphabetical letter or an underscore, not a number. Developers use the un
Variable names must not be a C# keyword. For example, these variable name declarations won't be allowed: f
Variable names are case-sensitive, meaning that string MyValue; and string myValue; are two different variables

Variable name conventions


Variable names should use camel case, which is a style of writing that uses a lower-case letter at the beginnin
word. For example: string thisIsCamelCase;.
Variable names should be descriptive and meaningful in your application. You should choose a name for your v
Variable names should be one or more entire words appended together. Don't use contractions, because the n
Variable names shouldn't include the data type of the variable. You might see some advice to use a style like s
don't follow this advice anymore.
What is C#?
Console
WriteLine()
() parenthesis
. Between Console and WriteLine()
.

What is a literal value?


What is literal suffix?

Literal types

What is a variable?

Not allowed while creating variable name


#

What are implicitly typed local variables?


You can only use the

escape character sequence?


Operator Overloading?
compound assignment operators

What is the .NET Class Library?

Stateful versus stateless methods

diff Console.WriteLine()
Random example

stateful
stateless
overloaded method
What is a code block?

Array?
C# is a case-sensitive language, meaning that the C# compiler considers the words console and Console as different as the w
is a class
is a method
is also know as method invocation operator.
is also know as Dot,Period , member access operator.
is also know as semicolon or end of statement operator.
Capitalize Console, Write, and Line
A literal value is a hard-coded value that never changes.
To create a decimal literal, append the letter m after the number. In this context, the m is called a literal suffix. -> Console.Wri
You can use either a lower-case m or upper-case M as the literal suffix for a decimal.
char literal
int literal
decimal literal
bool literal
string for words, phrases, or any alphanumeric data for presentation, not calculation
char for a single alphanumeric character
int for a whole number
decimal for a number with a decimal
bool for a true/false value
A variable is a data item that may change its value during its lifetime.
A variable is a friendly label that we can assign to a computer memory address. When we want to temporarily store a value in
# not allowed and $ not allowed
is also know as hash symbol, number symbol, pound symbol
it use camel case
An implicitly typed local variable is created using the var keyword, which instructs the C# compiler to infer the type. A
var keyword if the variable is initialized
var xyz; gives error Implicitly-typed variables must be initialized
An escape character sequence is a special instruction to the runtime that you want to insert a special character
Both string concatenation and addition use the plus + symbol. This is called overloading an operator,
Operators like +=, -=, *=, ++, and -- are known as
The += operator is specifically termed the addition assignment operator.
The .NET Class Library is a collection of thousands of classes containing tens of thousands of methods. These me
state describes the condition of the execution environment at a specific moment in time. As your code executes
execution, the current state of the application is the collection of all values stored in memory.
Some methods don't rely on the current state of the application to work properly. In other words, stateless meth
changing any values already stored in memory. Stateless methods are also known as static methods.

When calling a stateless method, you don't need to create a new instance of its class first.
When calling a stateful method, you need to create an instance of the class and access the method on the obje

instance method
static method
Console.WriteLine() method has 19 different overloaded versions.
A code block is a collection of one or more lines of code that are defined by an opening and closing curly brace symbol { }. It re
Two pipe characters || is the logical OR operator,
C# Arrays allow you to store sequences of values in a single data structure.
An array is a special type of variable that can hold multiple values of the same data type.
e that is stored in the memory address, we just use the variable name we created.

type had been used to declare the variable.

e character sequences begin with a backslash \ and then include another character.

n your applications.

r software system.

You might also like