C# Course – Codemeets– 02

Today we expect Variables, Data Types, Strings and working with Numbers. this all are we are doing C# console application. it use for get good basic knowledge for C sharp code.

C# Variables

Variable is a symbol that acts as a holder for various expressions or sizes and is often used to represent an arbitrary element of a set.

You now have a broader understanding. about what a variable is. So let us explain by c #. See below example.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
String chaName = "Harry";
int age = 30;

Console.WriteLine("my name is " + chaName);
Console.WriteLine("I am " + age);
Console.WriteLine("I like " + chaName);
Console.WriteLine("good for " + age);
Console.ReadLine();

}
}
}
output

This code Output is My Name is Harry. I am 30. I like Harry. good for 30. You can try this code your pc.

C# Data Types

This is special it use for make variables. c# is case sensitive language. We must first say that the type of data that the computer recognizes. There are a limited number of data types that we can identify.

Data Types:

  • Primitive Types: byte, sbyte, short, ushort, int, uint, long, ulong, float, double, decimal, bool, char
  • Non-Primitive Types: string, object, dynamic
  • Primitive types are value types and store data directly in memory
  • Non-primitive types are reference types and store a reference to the memory location in memory
Data TypeSyntax
StringString name = "Hello";
Charchar grade = 'A';
intint age = 30;
floatfloat gpa = 3.2f;
doubledouble gpa = 2.35686;
boolisMale = true;

Data Types

Strings

Strings do a lot of work. We can do it very beautifully and easily. This is very useful for tasks like changing a name. Get an understanding from the table below.

SyntaxOutput
Console.WriteLine ("hello world");hello world
Console.WriteLine ("hello \n world");hello
world
Console.WriteLine ("hello\"world");hello”world
String Ad = "hello" + "boy";
Console.WriteLine (Ad);
hello boy
String Ad = "Apple";
Console.WriteLine(Ad.Length);
5
Console.WriteLine(Ad.ToUpper());APPLE
Console.WriteLine(Ad.ToLower);apple
Console.WriteLine(Ad.Contains(“hp”);false
Console.WriteLine(Ad.Contains(“Apple”);true
Console.WriteLine(Ad.[3]);L
Console.WriteLine(Ad.Indexof(‘l’));3
Console.WriteLine(Ad.Substring(2));ple

Use for String

Work With Numbers

This allows us to see how the code makes various changes to the numbers. See the table below. Get ideas from it.

SyntaxOutput
Console.WriteLine(5+7);12
Console.WriteLine(Math.Abs (-40));40
Console.WriteLine(Math.Pow (4,2));16
Console.WriteLine(Math.Sqrt (144));12
Console.WriteLine(Math.Max (10,20));20
Console.WriteLine(Math.Min (10,20));10
Console.WriteLine(Math.Round(4.2));4
Console.WriteLine(Math.Sin(55));-0.99975517335862

Work with Numbers

More about Work with Numbers. example works.

SyntaxOutput
Console.WriteLine(8+6);14
Console.WriteLine(152-56);96
Console.WriteLine(80/5);16
Console.WriteLine(8%3);2
Console.WriteLine(8*3);24
Console.WriteLine((8+9)*(8+2));170

Operations

Now you have the basic knowledge of C sharp code. You can get a better understanding by trying the code again.

Thank for all!

More C# ClickHere!

See you Next C# Lesson Soon!

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

Translate »