stud
bud
Sign up
Log in
Home
Library
Explore
SAT
More
C# Questions Flashcards | StudBud
Explore
/
C# Questions
C# Questions
81 terms
·
StudBud Administration
·
24 plays
Imported from external platform
Flashcards
81 cards
F
Practice quiz
P
Host live
L
Questions
81
Answers
1
An ArrayList is:
An untyped list.
A generic list.
An array with listlike features.
2
Which of the following is used to create XML Documentation:
///
---
***
--
//
3
Which is true: (// returns)
char v1 = 'A'; char v2 = 'B';Console.WriteLine ( v1 + v2 ); // Error!
char v1 = 'A'; char v2 = 'B'; Console.WriteLine ( v1 + v2 ); // 131
char v1 = 'A'; char v2 = 'B';Console.WriteLine ( v1 + v2 ); // AB
4
Which are conventions for naming public variables?
Pascal casing: FirstName
Snake casing: first_name
Kebob casing: first-name
Mixed: firstName_long-version
Prefixed Camel casing: _firstName
Camel casing: firstName
5
Which of the following is used to process items Last In, First Out.
List
Stack
Dictionary
Queue
6
When using Visual Studio to create a new project you:
Select a template, then .NET Framework version, then select a C# version.
Select a template, then select a C# version.
Select a .NET Framework version, then select a C# version.
Select a template, then .NET Framework version.
7
decimal val1 = 123.56m; int num1 = (int)val1; (set num1 to 124 by rounding not truncating, which two will work?)
int num1 = (int)Math.Ceiling ( val1 );
int num1 =Math.Round ( val1, 0 );
int num1 = (int)Math.Round ( val1, 0 );
int num1 =Math.Ceiling ( val1 );
8
The four principles of object oriented programming are:
Inheritance
Polymorphism
Classes
Virtualization
Encapsulation
Abstraction
9
Which are conventions for naming interfaces?
Pascal casing: PrintableAddress
Prefixed Pascal casing: IPrintableAddress
Kebob casing: I-printable-address
Snake casing: I_printable_address
Camel casing: printableAddress
Prefixed Camel Casing: iPrintableAddress
10
You need to write a one line statement to set a variable to option “a” or option “b”. Which is the best solution:
int qty = ( item == "car" ) ? 1 : 2;
int qty = ( item == "car" ) : 1 ? 2;
int qty;if item== " car" ) { qty = 1; } else { qty = 2; }
int qty =iif (item== " car", 1, 2);
int qty = ( item == "car" ) then 1 else 2;
11
An analogy of a class might be:
A mold to create a set of identical objects.
A collection of objects.
A blueprint or plan to create objects.
A toolbox of tools to create objects.
12
You need to output 0,1,2,3,4,5,6,7,8,9. Which of the following work?
1
All of the above
3
2
13
Which is correct:
if ( price <> 100 ) {then do something…}
if ( price equals 100 ) {then do something…}
if ( price == 100 ) {then do something…}
if ( price = 100 ) {then do something…}
if ( priceeq 100 ) { then do something…}
14
Encapsulation is one of the fundamental concepts of object oriented programming:
True
False
15
When string name="Mike"; string city="Cincinnati"; decimal price = 5.125m; Which does not display a useful message:
string s = @"Hello {name} from {city} you owe {price}";
string s = "Hello " + name + " from " + city + " you owe " + price;
string s = $"Hello {name} from {city} you owe {price}";
string s = "Hello {name} from {city} you owe {price}";
16
The following code changes the Name property of the cust1object.
True
False
17
Given this series of numbers, what is the next number:
71
55
40
60
18
Which of the following are valid:
class Promotion :BankAccount , Customer, IBillable
class Promotion :BankAccount , Customer
class Promotion :BankAccount , IBillable , IPrintable
class Promotion :IBillable , IPrintable
19
You have a class named Animals. You want to create a class named Fish that inherits from Animals. Which code does this?
class Fish (Animals)
class Fish inherits Animals
class Fish of Animals
class Fish : Animals
20
Which is a valid string?
"c:\myfiles\training\"
$"c:\myfiles\training\"
@"c:\myfiles\training\"
$@"c:\myfiles\training\"
21
A namespace in your code is:
Defined by Microsoft. You must use the name they define for you.
Unique name to group yourclasses and distinguish from other developers code
The same as the name of your program.
Your company’s URL followed by your project name."com.MaxTrain.Payables"
22
Which of the following creates a variable containing a string?
var str = "abc";
string str = new String();
string str = "abc";
string str = "";
string str =anyKindOfObject .ToString();
string str =String.Empty;
23
Which of the following is true?
All classes must have a Main method.
Each class must be stored in its own file. Product--> product.cs
Class files have an extension of.class.
Classes used by other classes must be stored in the same file.
None of the above
24
Which of the following is a valid statement?
1
2
4
3
25
Which are conventions for naming classes, structs and records?
Kebobcasing: first-name
Mixed: firstName_long-version
Snake casing: first_name
Pascal casing: FirstName
Prefixed Camel casing: _firstName
Camel casing: firstName
26
Which is the C# True/False data type?
bit
bool
yesno
Bool
Boolean
boolean
27
Which have valid syntax: (can be more than one)
if( qty > 5 ) { msg = "Discount!"}
if qty > 5 { msg = "Discount!"; }
if ( qty > 5 ) { msg = "Discount!"; }
if ( qty > 5 ) msg = "Discount!";discount = .02m;
if( qty > 5 ) msg = "Discount!";
if ( qty > 5 ) { msg = "Discount!"; discount = .02m; }
28
Which of the following are publicly exposed in a well-designed class?
Methods
Properties
Fields
Snippets
Strings
29
Which of these will work?
decimal val1 = 123.45m; int num1 = (int)val1;
decimal val1 = 123.45m; int num1 = val1.ToInt();
decimal val1 = 123.45m; int num1 = int.Parse (val1);
decimal val1 = 123.45m; int num1 = val1;
30
Which of the following is used to quickly look up items by a key/keword.
Dictionary
Queue
List
Stack
31
Which of the following is a C# data type?
Int
Int32
int
Text
32
Which of the following allows “x” to have null as a value:
int x = 5;
nullableintx = 5;
Nint= 5;
int? x = 5;
nullint= 5;
33
To round a number to two decimal places:
decimal x = 5.125m;Console.WriteLine ( math.Round (x, 2) );
decimal x = 5.125m;Console.WriteLine ( Round(x, 2) );
decimal x = 5.125m;Console.WriteLine ( Decimal(x, 2) );
decimal x = 5.125m;Console.WriteLine ( x.Round (2) );
decimal x = 5.125m;Console.WriteLine ( Math.Round (x, 2) );
34
Casey is your favorite classmate.
True
False
35
Which versions of .NET are still in long term support (LTS).
3.0
5.0
6.0
3.1
36
Which are conventions for naming public methods?
Snake casing: first_name
Mixed: firstName_long-version
Pascal casing: FirstName
Prefixed Camel casing: _firstName
Kebobcasing: first-name
Camel casing: firstName
37
The first word in the following code fragment defines:
BankAccount
ba1 = new BankAccount();
A C# convention
The name of the file that contains the class definition.
The datatype of the new variable.
The object being stored in the new variable.
38
A Snipit is:
A C# feature
A Visual Studio feature
Code copied from the internet
39
What is the name of this pattern: int qty = ( item == "car" ) ? 1 : 2;
Ternary
Immediate IF
Dynamicvariable assignmen t
Inline IF
40
What is NuGet?
A repository of packages for Visual Studio.
Part of the GitHub repository system.
A C# extension that adds support forSystem.Speech
A way to create modular programs using nuggets.
41
Benefits of a Generic list:
Can be expanded at any time.
Anything can be stored in a single list. (It’s generic!)
Faster and more memory efficient than arrays.
Less chance of code errors.
42
When creating class code the “static” keyword on the class means: public static class WeatherFunctions ()
Once the class has been created, it cannot be changed.
Class is optimized to be stored once in static memory and can't be moved
The variables in the class cannot be changed once created.
An instance of the class cannot be created. (Class can't be instantiated)
43
StringBuilder is:
The fastest way to concatenate 1000’s of strings.
The only way to concatenate 1000’s of strings.
The best way to concatenate all strings.
44
Which of the following is used to process items First In, First Out.
Stack
Queue
Dictionary
List
45
Which is an example of a generic list:
List<int> mylist2 = new List<int>() { 43, 234, 54, 346, 12, 43, 2, 345 };
ArrayList mylist3 = new ArrayList () { 43, 234, 54, 346, 12, 43, 2, 345 };
int[] Queue = { 43, 234, 54, 346, 12, 43, 2, 345 };
int[] mylist1 = { 43, 234, 54, 346, 12, 43, 2, 345 };
46
Which are valid ways of creating a new object?
Product() prod1 = new Product();
var prod1 = new Product();
new Product = Product();
Product prod1 = new();
Product prod1 = new Product();
47
Which are conventions for naming private or internal variables?
Prefixed Camel casing: _firstName
Snake casing: first_name
Camel casing: firstName
Pascal casing: FirstName
Mixed: firstName_long-version
Kebobcasing: first-name
48
A class constructor? (could be more than one)
Is called every time a class instance is referenced.
Is required in every class.
Is called only during the creation of an object (instance of a class).
49
Which of the following is a valid statement?
2
1
3
4
50
Which of the following versions of .NET require an upgrade to Visual Studio 2022?
7.0
5.0
3.0
3.1
6.0
51
decimal val1 = 123.56m;int num1 = (int)val1; (After running this code, what’s the value of num1?)
123
Error
123.56
124
52
Which of the following is not a valid C# / .NET type pair?
decimal / Decimal
long / Int64
int / Int32
byte / Byte
float / single
long / Int128
53
An example of an IDE is:
PowerShell.
Notepad, plus dotnet.exe plus SQL Server.
Visual Studio.
A collection of methods, properties and fields.
54
Which of these will work?
string val1 = "123";int num1 = val1.ToNumber();
string val1 = "123"; int num1 = (int)val1;
string val1 = "123"; int num1 = val1;
string val1 = "123"; int num1 = int.Parse (val1);
55
Which languages support the concept of classes?
C#
JavaScript
Java
C++
C
56
Which of the following is true? int price = 0; const int regions = 6;
const is a type of variable.
A const cannot be changed by other code.
A const can only be changed by a constructor.
57
Which of the following is true?
int x =10;int y = x++; The value of y is 11
int x =10;int y = x++; The value of y is 10
int x =20;int y = ++x; The value of y is 21
int x =20;int y = ++x; The value of y is 20
58
Which of the following is usually the best choice for money?
float / single
decimal / Decimal
int / Int32
byte / Byte
long / Int64
59
Which of the following will create May 1st 2022?
DateTimemydate = "05/01/2022";
DateTimemydate = new DateTime (2022,5,1);
DateTimemydate = DateTime.Parse ("2022/05/01");
DateTimemydate = DateTime.Parse ("05/01/2022");
DateTimemydate = new DateTime (5, 1, 2022);
60
The following code sample is a: public string Name { get; set; }
Field
Full property
A Getter/Setter method
Self-implementing or auto property
61
Which will be true for only customers in Ohio or Kentucky with abalance greater than 1000 and is inactive?
(state == "OH" || state == "KY") && balance > 1000 && inactive
state == "OH" || state == "KY" && balance > 1000 && inactive
(state == "OH" OR state == "KY") AND balance > 1000 AND inactive
state == "OH" || state == "KY" && (balance > 1000 && inactive)
state == "OH" OR state == "KY" AND balance > 1000 AND inactive
state == "OH" OR state == "KY" AND (balance > 1000 AND inactive)
62
Which of these will work?
int val1 = 123; decimal num1 = decimal.Parse (
int val1 = 123; decimal num1 = val1;
int val1 = 123; decimal num1 = val1.ToDecimal();
int val1 = 123; decimal num1 = (decimal)val1;
63
Which is an example of a property?
public int ReorderLevel {}
public string Region() { get; set; }
public void GetPrice ()
public string Name { get; set; }
int _qty; public int Qty { get { return _qty; } set { _qty = value; }
64
Which is a valid string?
[Hello world!]
'Hello world!'
"Hello world!"
65
What is wrong with this code? It won’t compile.
Missing parentheses
Missing break
Missing semicolon
Missing curly brace
66
Which is an example of a constructor for the Vendor class?
public void Vendor() {}
public VendorNewVendor ()
public Vendor() {}
private Vendor() {}
public voidNewVendor ()
67
cust1 == cust2
True
False
68
You need to output 0,1,2,3,4,5,6,7,8,9. Which of the following work?
3
All of the above
1
2
69
If the customer is in Ohio, then we want to set balance to 100. Which is correct?
if ( state = "OH" ) { balance = 100; }
if ( state == "OH" ) { balance == 100; }
if ( state = "OH" ) { balance == 100; }
if ( state == "OH" ) { balance = 100; }
70
The following code changes the Name property of the cust1object.
True
False
71
.
Both
2
1
72
A C# int / .NET Int32 needs how many bytes to store?
16
4
8
2
73
Which of the following is true? int price = 0; readonly int regions = 6;
A readonly cannot be changed by other code.
readonly is a type of variable.
A readonly can only be changed by a constructor or when declared.
74
Everybody in the office (5 ppl) needs 1 computer ($300), 5 pens ($3 each) and 3 notebookes ($2 each). Which is correct?
int cost = 5 * 300 + 5 * 3 + 3 * 2;
int cost = 5 * (300 + (5 * 3) + (3 * 2));
int cost = (5 * 300) + 5 * 3 + 3 * 2;
int cost = 5 * (300 + 5 * 3 + 3 * 2);
int cost = 5 * 300 + (5 * 3 + 3 * 2);
75
If 5/1/1990 is your birth dates, whatis this calculating?
The current date and time.
Your age in years.
Your age in months.
Your age in days.
76
Is the following true: cust1 == cust2
True
False
77
Which part of these statements is the “instance”?
BankAccount ba1 = new BankAccount
BankAccount ba1 = new BankAccount ();
BankAccount ba1 = new BankAccount();
78
Which of the following is a valid statement?
1
4
2
3
79
The developer using a class you have created must be able to see thesource code of the class to be able to use the class
False
True
80
Analogies for an Interface:
A constraint
A port on a computer
A class
A blueprint
A contract
81
A class-level variable:
Is declared inside of a class, but outside of any methods.
Is declared inside of methods.
Is declared inside of a constructor.
Is declared outside of a class but inside of a namespace.