¡GoConqr estrena diseño! Cuéntanos qué te parece.

Apuntes

Programming basics

Kyle Whitbread Inglés 4 páginas

Contenido del apunte (4)

Página 1

//Read-Write to file.

String text = System.IO.File.ReadAllText(@"C://User etc)

//Display File contents.

String[] Lines = System.IO.File.ReadAllLines(@"C://User)

Base & Derived classes

A derived class, in the context of C#, is a class created or derived from another existing class. The existing class from which the derived class gets created through inheritance is known as base or superclass.

While inheriting from a base class, the derived class implicitly inherits all the members (except constructors and destructors) which it reuses, extends and modifies the behavior of the base class. The derived class overrides the properties and methods of the base class so that it represents the specialized version of a base class. C# provides the ability to override and hide methods of a base class in the derived class which makes both classes to evolve freely and maintains binary compatibility.

As & IS

Is Operator checks the validity or an object or method, to see when

Página 2

Lists:

List listed = new List();

listed.Add("Hello");

listed.Add("2");

listed.Add("3");

listed.Add("4");

Console.WriteLine(listed.Count); // Counts the ammount of Strings in the list.

(listed[0])

/* listed.Remove("");

foreach (string myList in listed)

{

Console.Write(myList + " ");

}

Console.WriteLine();

*/

Arrays

string[] sentence = new string[4] {"The", "Quick", "Brown", "Fox", };

foreach (string word in sentence)

{

Console.Write("{0}", word);

}

Console.Writeline();

)

string[,] names = new string[3,2] { {"John", "Smith",}, {"Anna", "Smith",}, {"Sally", "Jones"} };

console.Writeline(names[1,0], names[1,1]);

for (int j = 0; int j < names.getLength; j++)

{

int k = 0;

console.write("{0}, {1}", names[j, k], names[j, k+1]

k++;

Queue:

Queue MyQueue = new Queue();

MyQueue.Enqueue(10);

MyQueue.Enqueue(100);

MyQueue.Enqueue(500); MyQueue.Enqueue(1000);

if (MyQueue.Contains(500)) { Console.WriteLine("Found you 500"); }

foreach (int i in MyQueue) { Console.WriteLine(i); }

int[] myArray = new int[MyQueue.Count];

MyQueue.CopyTo(myArray, 0); //Copy Que to array.

foreach (int j in myArray)

{

Console.WriteLine(j);

}

Linked lists:

LinkedList MyLL = new LinkedList();

MyLL.AddLast("Orange");

MyLL.AddFirst("Apple");

MyLL.AddLast("Cherry");

MyLL.AddFirst("Banana");

LinkedListNode i = MyLL.Find("Banana");

MyLL.AddBefore(i, "Fruit:");

MyLL.Remove("Banana");

foreach (var fruit in MyLL)

{

Console.WriteLine(fruit);

}

Página 3

Basic programming techniques

Console.WriteLine("Please input value");

string input = Console.ReadLine(); // read string from the console

Console.WriteLine("You entered: {0}", input);

int num;

if (int.TryParse(input, out num)) //Try to pass string to int)

{

Console.Write("Multiply by 1000: ");

Console.WriteLine(num * 1000);

}

else

{

Console.WriteLine("Value was not an integer");

}

Randomization

Random random = new Random(); //Initialise Random

string fruit; //Fruit Variable

for (int i = 0; i < 10; i++) //For Loop

{

int randomNumber = random.Next(0, 3); // Amount of random instances of fruit

switch (randomNumber)

{

case 0:

fruit = "An Apple";

break;

case 1:

fruit = "An Orange";

break;

case 2:

fruit = "A Pear";

break;

default:

fruit = "Not a fruit";

return;

}

Console.WriteLine("I think you should have {0}", fruit);

}

Random List:

int[] RandomNums = new int[100]; //Array called RandomNums

byte k = 0;

Random random = new Random(); //Random instance

bool addToArray = true; //Adds numbers to array

while (k < 100)

{

int randomNumber = random.Next(1, 101); //Scope of random numbers

addToArray = true; //Adding to array (Yes)

for (int l = 0; l < k; l++)

{

if (RandomNums[l] == randomNumber) //If the number has already appear add to array (No)

{

addToArray = false;

break;

}

}

if (addToArray = true) //If it adds to the array carry on

{

RandomNums[k] = randomNumber;

k++;

}

}

Console.WriteLine(Environment.NewLine + "length: " + RandomNums.Length + Environment.NewLine);

foreach (int i in RandomNums) //Outputs random numbers.

{

Console.Write("{0} ", i);

}

Console.WriteLine(Environment.NewLine + Environment.NewLine);

Página 4

HTML , StyleSheets & CSS

<!DOCTYPE html> //type of document

<html lang="en">

<head> //Head of the document, headers, links to external documents or style sheets.

<meta charset="UTF-8">

<title>Title</title>

<link rel="Stylesheet" type="text/css" href="styles.css" /> //Ref to style sheet

</head>

<body> //Contains page code.

<h1>Welcome to my website</h1>

<div id="div1">DIV1</div> //Classes for HTML

<div id="div2">DIV2</div>

</body>

</html>

h1 //SS for H1

{

font-family: Arial;

font-size: 50px;

}

#div1 //Div class modifyer ref class using #

{

width: 150px;

height: 150px;

background-color: #ff7c26;

font-family: Arial;

font-size: 20px;

color: yellow;

}

}

#div2

{

width: 150px;

height: 150px;

background-color: #2c1cff;

font-family: Arial;

color: #0004ff;

}

Información

Descripción
Apunte sobre Programming basics, creado por Kyle Whitbread el 08/04/2018.
Creado por
Kyle Whitbread · abr 2018
Actualizado
27 abr 2018
Visitas
5
Valoración

Más sobre Input, Output and File Handling

Escríbenos

¿Sobre qué es tu mensaje?

¿Qué te parece el nuevo diseño?

¿Te gusta?