String Interpolation:
Example:
class StringInterpolation
{
static void Main(string[] args)
{
Console.WriteLine(“Hello World”);
int a = 98;
Console.WriteLine(“Number is ” +
a);
string
name = “Dollar”;
Console.WriteLine($"Name is {name}");
/* If you put the $ symbol at the beginning of the string, it will be treated as the evaluated string(Sting Interpolation). Which string do you want to evaluate that string we need to wrap into the curly braces ({}).*/
}
}
var:
var is a keyword, it is used to declare an implicit type variable, that
specifies the type of a variable based on the initial value.
Example:
class Testing
{
public static void Main(string[] args)
{
var age = 22;
var name = "Testing Colleges";
var gen = 'M';
var sal = 8.25f;
Console.WriteLine($"Name: {name} Age: {age}
Gender: {gen} Salary: {sal}");
}
}
dynamic type:
dynamic type, the same work as a var keyword but here we can
change the value to one datatype to another data type at run
time.
Example:
class TestingDynamic
{
public static void Main(string args[])
{
dynamic height = 5.8f;
Console.WriteLine("Height is:"+height);
height = "Tall";
Console.WriteLine("Height
is:"+height);
}
}
Methods:
- Methods should be created outside the Main method.
- To call any method from we must create an object for that class.
- Syntax: ClassName Object = new Constructor();
- Example: Testing obj = new Testing();
Inheritance:
In Java, we will use the "extends" keyword to connect the child-class and parent-class but in C# we will use just “:” (colon) to connect the classes.
Example: class Child : Parent
ArrayList:
If you don’t know how many variables to store in the array then we will use an array list.
Example:
class ArrayListExm
{
public static void Main(string args[])
{
ArrayList a = new ArrayList();
a.Add(“Automation”);
a.Add(“Manual”);
a.Add(“CSharp”);
Console.WriteLine(a[1]);
}
}
Output: Manual
foreach loop:
Example:
class ArrayListExm
{
public static void Main(string
args[])
{
ArrayList a =
new ArrayList();
a.Add(“Automation”);
a.Add(“Manual”);
a.Add(“CSharp”);
Console.WriteLine(a[1]);
//To print all the values
foreach(String item in a)
{
Console.WriteLine(item);
}
}
}
No comments:
Post a Comment