Greife auf kostenlose Karteikarten, Zusammenfassungen, Übungsaufgaben und Altklausuren für deinen Programming fundamentals Kurs an der Radboud University zu.
What does the WriteLine method do?
This method prints out (output) the information (variables, integers, doubles en string and much more) on the screen and does this always on a new line. The Console.Write method prints out information but does this always on the same line.
How many bits is a byte?
A byte is 8 bits.
What is a class?
It is a group that contains data and methods. They are contained within braces tha belong to the namespace. It is like a classification system.
How would you create the constructor with arguments?
class Cost
{
private double amount;
private double price;
public Cost(double a) // This is the constuctor
{
amount = a;
price = .35;
}
public double Calc() // This is a method to include a return value of a calculation
{
return amount * price;
}
}
// Now you can call the constuctor with an object.
Give an example of how to code a namespace.
using System;
namespace Csharp_namespace
{
class MyClass
{
public MyClass()
{
Console.WriteLine("My Class");
}
}
}
class MyClient
{
public static void Main()
{
//Using the fully qualified name to access the namespace member.
Csharp_namespace.MyClass mc = new
Csharp_namespace.MyClass();
}
}
Give an example of using 2 or more different namespaces with the same classes.
using System;
// Nested Namespace
namespace MyNamespace
{
namespace Nested
{
public class SampleClass
{
public static void myMethod()
{
Console.WriteLine("Nested Namespace Example");
}
}
}
}
namespace MyProgram
{
public class MyClass
{
public static void Main()
{
MyNamespace.Nested.SampleClass.myMethod();
}
}
}
What are some things you have to remember about a constructor?
1. The constructor name must match the class name, and it cannot have a return type (like void or int).
2. The constructor is called when the object is created.
3. All classes have constructors by default: if you do not create a class constructor yourself, C# creates one for you. However, then you are not able to set initial values for fields.
How can you create a method?
1. within the class code block create '(you could also add public if you want to use it outside the class) "static void myMethod() {}"
2. within the curly brackets of myMethod() add the code you'd want.
3. you can add parameters in between the parenthesis of myMethod(), for example;
static void myMethod(string fname)
{
Console.WriteLine(fname + "you are it!");
}
4. You can call the method in the static void Main(string[] args){} method.
What does args in the main method stand for?
It is a parameter in the main method that accesses a string array that is called args, this is in array that is populated with several command-line arguments from the operating system. This makes configurating programs less complex.
Give an example of constuctor overloading;
// C# program to Demonstrate the overloading of
// constructor when the types of arguments
// are different
using System;
class ADD {
int x, y;
double f;
string s;
// 1st constructor
public ADD(int a, double b)
{
x = a;
f = b;
}
// 2nd constructor
public ADD(int a, string b)
{
y = a;
s = b;
}
What is important for the writeline method to work?
1. You have to write the message within openening and closing parenthesis (). This is the containter for the information.
2. You have to write everything between double quotes, with the exception of variables and so on.
3. Every output of the writeline method is always in string datatype.
How many byte is a kilobyte?
A kilobyte is 2^10 bytes or also 1024 bytes.
Greife kostenlos auf tausende geteilte Karteikarten, Zusammenfassungen, Altklausuren und mehr zu.
Jetzt loslegen