Mh114
Data Pipeline Engineer
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
400 XP
This tutorial, we will create and describes string arrays and it randoms the quotes shows how they work in C# .net. In C# .net, you can use strings as array of characters, However, more common practice is to use the string keyword to declare a string variable. This is the basic implementation for a newbie in programming who plans to build a system in the future.
Sample Code
String Arrays Sample code
For creating a random quote, here is the syntax.
Hope its help to all beginners and professional, Learn and enjoy the programming.
Thanks!
Download
Sample Code
String Arrays Sample code
- using System
;
- using System
.
Collections.
Generic;
- public
class
GenericSample
- {
- public
static void Main(
string[
]
args)
- {
- List<
string>
list
=
new
List<
string>
(
)
;
- list
.
Add(
"First string"
)
;
- list
.
Add(
"Second string"
)
;
- list
.
Add(
"Third string"
)
;
- list
.
Add(
"Fourth string"
)
;
- for
(
int n =
0
;
n <
list
.
Count
;
n++
)
- {
- Console.
WriteLine(
list
[
n]
)
;
- }
- }
- }
For creating a random quote, here is the syntax.
- using System
;
- using System
.
Collections.
Generic;
- public
class
RandomQuotes
- {
- static void CreateQuotes(
List<
string>
quotes)
- {
- quotes.
Add(
"I Hate Drugs!!!@Weed"
)
;
- quotes.
Add(
"Long if its hot, short if its cold...@Popstickle"
)
;
- quotes.
Add(
"John 3:16@Verse"
)
;
- quotes.
Add(
"Good Bye!!!@Welcome"
)
;
- quotes.
Add(
"HAHAHA :P !!!@Bleee"
)
;
- }
- static void PrintQuote(
string quote)
- {
- string[
]
substring =
quote.
Split
(
'@'
)
;
- Console.
WriteLine(
substring[
0
]
)
;
- Console.
WriteLine(
"-"
+
substring[
1
]
)
;
- }
- static string GetRandomQuote(
List<
string>
quotes)
- {
- int n =
new
Random(
)
.
Next
(
0
,
quotes.
Count
)
;
- return
(
quotes[
n]
)
;
- }
- public
static void Main(
string[
]
args)
- {
- List<
string>
list
=
new
List<
string>
(
)
;
- CreateQuotes(
list
)
;
- string myRandomQuote =
GetRandomQuote(
list
)
;
- if
(
args.
Length ==
0
)
- {
- Console.
WriteLine(
"Error Argument:\n
* All\n
* Random\n
* Search"
)
;
- return
;
- }
- if
(
args[
0
]
==
"random"
)
- {
- PrintQuote(
myRandomQuote)
;
- }
- else
if
(
args[
0
]
==
"all"
)
- {
- int x =
0
;
- for
(
int n =
list
.
Count
;
n >
0
;
n--
)
- {
- PrintQuote(
list
[
x]
)
;
- x++;
- }
- }
- }
- }

Hope its help to all beginners and professional, Learn and enjoy the programming.
Thanks!
Download
You must upgrade your account or reply in the thread to view the hidden content.