0% found this document useful (0 votes)
16 views3 pages

C# .Cs Extension: Run/build

Uploaded by

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

C# .Cs Extension: Run/build

Uploaded by

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

C# .

cs extension
Run/build
File -> project -> console app C# select version
*.cs  C# compiler  *.d
ll (Dynamic Link Library)

Shortcut Keys
Copy Ctrl C Show Quick- fixes Alt Enter Find in File Ctrl F
Paste Ctrl V Save File Ctrl S Find in all Ctrl Shift F
Cut Ctrl X See all Ctrl Shift S Replace Ctrl H
Duplicate Ctrl D Quick Watch Shift F9 Replace in all Ctrl Shift H
Select all Ctrl A Toggle Breakpoint F9 Go back Ctrl -
Rename Ctrl R R Step over F10 Mouse
Comment Ctrl K C Step into F11 Go to def Ctrl click
Uncomment Ctrl K U Undo Change Ctrl Z Multiline select Alt Drag
Code cleanup Ctrl K D Redo Change Ctrl Y

Variable-> First digit can’t be digit


var is a keyword, it is used to declare an implicit type variable, that specifies the type of a variable based on initial
value.
USER INPUT
 String userChoice = Console.ReadLine(); Console.WriteLine(“User input:” + userChoice);
Scopes
Global Scope: Variables/constants in a namespace, accessible everywhere within it.
Class Scope: Variables/constants/methods in a class, accessible within the class.
Method Scope: Variables declared in a method, accessible only within that method.
Block Scope: Variables declared in a block of code, accessible within that block.
Local Scope: Method parameters/variables in a block, accessible only within the block.
Array -> Default it is assigned to 0

String interpolation is a feature in C# that allows you to embed expressions or variables directly within a string literal.
int x = 10; int y = 5;
string result = $"The sum of {x} and {y} is {x + y}.";
Console.WriteLine(result);
*************************************************************************************************
Drawback of single
using System;
using System.Threading;

namespace MultiThreadingInCSharp
{
class ProgramP
{
static void Main(string[] args)
{
Method1();
Console.WriteLine("MEthod 1 execution is completed");
Method2();
Console.WriteLine("Method 2 execution is completed");
Method3();
Console.WriteLine("MEthod 3 execution is completed");
//Single thread
//Thread t =Thread.CurrentThread;
//t.Name = "Main Thread";
//Console.WriteLine($"Thread name {t.Name}");
//Console.WriteLine("My current thread-"+ Thread.CurrentThread.Name);
}
static void Method1()
{
for (int i = 1; i <= 5; i++)
{
Console.WriteLine("Method 1 :" + i);
}
}
static void Method2()
{
for (int i = 1; i <= 5; i++)
{
Console.WriteLine("Method 2 :" + i);
if (i == 2) { Console.WriteLine("executing code Started");
Thread.Sleep(10000);
Console.WriteLine("executing code Completed");
}
}
}
static void Method3()
{
for (int i = 1; i <= 5; i++)
{
Console.WriteLine("Method 3 :" + i);
}
}
}
}Its using single thread its going line by line

***********************************MULTITHREAD**************************************************
using System;
using System.Threading;

namespace MultiThreadingInCSharp
{
class ProgramP
{
static void Main(string[] args)
{
//Creating Threads
Thread t1 = new Thread(Method1)
{
Name = "Thread 1"
};
Thread t2 = new Thread(Method2);
t2.Name = "Thread 2";

Thread t3 = new Thread(Method3)


{
Name = "Thread 3"
};
t1.Start();
t2.Start();
t3.Start();
Console.WriteLine("Main Thread Ended");
//Method1();
//Console.WriteLine("MEthod 1 execution is completed");
//Method2();
//Console.WriteLine("Method 2 execution is completed");
//Method3();
//Console.WriteLine("MEthod 3 execution is completed");
//Single thread
//Thread t =Thread.CurrentThread;
//t.Name = "Main Thread";
//Console.WriteLine($"Thread name {t.Name}");
//Console.WriteLine("My current thread-"+ Thread.CurrentThread.Name);
}
static void Method1()
{
Console.WriteLine("Method 1 Started using "+ Thread.CurrentThread.Name);
for (int i = 1; i <= 5; i++)
{
Console.WriteLine("Method 1 :" + i);
}
Console.WriteLine("Method 1 Ended using-->" + Thread.CurrentThread.Name);
}
static void Method2()
{
Console.WriteLine("Method 2 Started using " + Thread.CurrentThread.Name);
for (int i = 1; i <= 5; i++)
{
Console.WriteLine("Method 2 :" + i);
if (i == 2)
{
Console.WriteLine("executing code Started");
Thread.Sleep(10000);
Console.WriteLine("executing code Completed");
}
}
Console.WriteLine("Method 2 Ended using-->" + Thread.CurrentThread.Name);
}
static void Method3()
{
Console.WriteLine("Method 3 Started using " + Thread.CurrentThread.Name);
for (int i = 1; i <= 5; i++)
{
Console.WriteLine("Method 3 :" + i);
}
Console.WriteLine("Method 3 Ended using-->" + Thread.CurrentThread.Name);
}

}
}

You might also like