need to convert code for pick random line and display
I'm working hard on my new project, I'm totally new in C# so I don't really understand much, and I'm making a loading screen now, and do you know that "Loading message".
So I would like to make a few lines, and the code should be able to pick a random line and display when it is loading. Like this example:
var randomLoadingMessage = function() {
var lines = new Array(
"Locating the required gigapixels to render...",
"Spinning up the hamster...",
"Shovelling coal into the server...",
"Programming the flux capacitor"
);
return lines[Math.round(Math.random()*(lines.length-1))];
}
I found it on the internet. How could I use it on c#?
I need help to do something similar in c#
c#
|
show 10 more comments
I'm working hard on my new project, I'm totally new in C# so I don't really understand much, and I'm making a loading screen now, and do you know that "Loading message".
So I would like to make a few lines, and the code should be able to pick a random line and display when it is loading. Like this example:
var randomLoadingMessage = function() {
var lines = new Array(
"Locating the required gigapixels to render...",
"Spinning up the hamster...",
"Shovelling coal into the server...",
"Programming the flux capacitor"
);
return lines[Math.round(Math.random()*(lines.length-1))];
}
I found it on the internet. How could I use it on c#?
I need help to do something similar in c#
c#
2
Welcome to Stack Overflow! You seem to be asking for someone to write some code for you. Stack Overflow is a question and answer site, not a code-writing service. Please see here to learn how to write effective questions.
– Arthur Attout
Nov 13 '18 at 15:11
2
Possible duplicate of Pick Random String from Array
– Amy
Nov 13 '18 at 15:18
2
I guess people expect you to learn the basics of c# before asking questions... Otherwise you'll have a hard time understanding the answers and do modifications to them to fit your needs.
– Oram
Nov 13 '18 at 15:27
1
Hi there, the thing you are trying to do can be achieved. quite easily. But, to use the C# language more efficiently, spend some time in MSDN for conceptualization. I am sure that will help you a lot :)
– Tazbir Bhuiyan
Nov 13 '18 at 15:27
2
If you want someone to write you some code there are paid platforms for that.. this is a Q&A site
– Maor Refaeli
Nov 13 '18 at 15:43
|
show 10 more comments
I'm working hard on my new project, I'm totally new in C# so I don't really understand much, and I'm making a loading screen now, and do you know that "Loading message".
So I would like to make a few lines, and the code should be able to pick a random line and display when it is loading. Like this example:
var randomLoadingMessage = function() {
var lines = new Array(
"Locating the required gigapixels to render...",
"Spinning up the hamster...",
"Shovelling coal into the server...",
"Programming the flux capacitor"
);
return lines[Math.round(Math.random()*(lines.length-1))];
}
I found it on the internet. How could I use it on c#?
I need help to do something similar in c#
c#
I'm working hard on my new project, I'm totally new in C# so I don't really understand much, and I'm making a loading screen now, and do you know that "Loading message".
So I would like to make a few lines, and the code should be able to pick a random line and display when it is loading. Like this example:
var randomLoadingMessage = function() {
var lines = new Array(
"Locating the required gigapixels to render...",
"Spinning up the hamster...",
"Shovelling coal into the server...",
"Programming the flux capacitor"
);
return lines[Math.round(Math.random()*(lines.length-1))];
}
I found it on the internet. How could I use it on c#?
I need help to do something similar in c#
c#
c#
edited Nov 13 '18 at 17:17
Tazbir Bhuiyan
1,3441324
1,3441324
asked Nov 13 '18 at 15:07
Dziu GasDziu Gas
35
35
2
Welcome to Stack Overflow! You seem to be asking for someone to write some code for you. Stack Overflow is a question and answer site, not a code-writing service. Please see here to learn how to write effective questions.
– Arthur Attout
Nov 13 '18 at 15:11
2
Possible duplicate of Pick Random String from Array
– Amy
Nov 13 '18 at 15:18
2
I guess people expect you to learn the basics of c# before asking questions... Otherwise you'll have a hard time understanding the answers and do modifications to them to fit your needs.
– Oram
Nov 13 '18 at 15:27
1
Hi there, the thing you are trying to do can be achieved. quite easily. But, to use the C# language more efficiently, spend some time in MSDN for conceptualization. I am sure that will help you a lot :)
– Tazbir Bhuiyan
Nov 13 '18 at 15:27
2
If you want someone to write you some code there are paid platforms for that.. this is a Q&A site
– Maor Refaeli
Nov 13 '18 at 15:43
|
show 10 more comments
2
Welcome to Stack Overflow! You seem to be asking for someone to write some code for you. Stack Overflow is a question and answer site, not a code-writing service. Please see here to learn how to write effective questions.
– Arthur Attout
Nov 13 '18 at 15:11
2
Possible duplicate of Pick Random String from Array
– Amy
Nov 13 '18 at 15:18
2
I guess people expect you to learn the basics of c# before asking questions... Otherwise you'll have a hard time understanding the answers and do modifications to them to fit your needs.
– Oram
Nov 13 '18 at 15:27
1
Hi there, the thing you are trying to do can be achieved. quite easily. But, to use the C# language more efficiently, spend some time in MSDN for conceptualization. I am sure that will help you a lot :)
– Tazbir Bhuiyan
Nov 13 '18 at 15:27
2
If you want someone to write you some code there are paid platforms for that.. this is a Q&A site
– Maor Refaeli
Nov 13 '18 at 15:43
2
2
Welcome to Stack Overflow! You seem to be asking for someone to write some code for you. Stack Overflow is a question and answer site, not a code-writing service. Please see here to learn how to write effective questions.
– Arthur Attout
Nov 13 '18 at 15:11
Welcome to Stack Overflow! You seem to be asking for someone to write some code for you. Stack Overflow is a question and answer site, not a code-writing service. Please see here to learn how to write effective questions.
– Arthur Attout
Nov 13 '18 at 15:11
2
2
Possible duplicate of Pick Random String from Array
– Amy
Nov 13 '18 at 15:18
Possible duplicate of Pick Random String from Array
– Amy
Nov 13 '18 at 15:18
2
2
I guess people expect you to learn the basics of c# before asking questions... Otherwise you'll have a hard time understanding the answers and do modifications to them to fit your needs.
– Oram
Nov 13 '18 at 15:27
I guess people expect you to learn the basics of c# before asking questions... Otherwise you'll have a hard time understanding the answers and do modifications to them to fit your needs.
– Oram
Nov 13 '18 at 15:27
1
1
Hi there, the thing you are trying to do can be achieved. quite easily. But, to use the C# language more efficiently, spend some time in MSDN for conceptualization. I am sure that will help you a lot :)
– Tazbir Bhuiyan
Nov 13 '18 at 15:27
Hi there, the thing you are trying to do can be achieved. quite easily. But, to use the C# language more efficiently, spend some time in MSDN for conceptualization. I am sure that will help you a lot :)
– Tazbir Bhuiyan
Nov 13 '18 at 15:27
2
2
If you want someone to write you some code there are paid platforms for that.. this is a Q&A site
– Maor Refaeli
Nov 13 '18 at 15:43
If you want someone to write you some code there are paid platforms for that.. this is a Q&A site
– Maor Refaeli
Nov 13 '18 at 15:43
|
show 10 more comments
1 Answer
1
active
oldest
votes
Here are the pieces you need to solve this
- A Program. Below is the boilerplate code for a C# console application. Why's this needed? So your line of code has some context to run in. NB: You could run code via LinqPad without this, or you could use a different type of project to host your code; but for now I'm keeping things simple.
using System;
public class Program
{
public static void Main()
{
Console.WriteLine("Hello World");
}
}
- An array holding the strings you want to display. See Options for initializing a string array for additional info / options:
string lines = new {
"Locating the required gigapixels to render...",
"Spinning up the hamster...",
"Shovelling coal into the server...",
"Programming the flux capacitor"
);
- A way to pick one of these strings at random. You get a string from the array by putting a number (the index) in square brackets after the variable name, with each item in the array having consecutive numbers starting at 0. ; e.g.
lines[1]would give you the string"Spinning up the hamster...". You can get a random number using an instanceRandomclass'sNextmethod. This method requires you to provide parameters to define the range in which the result should fall. The method returns adoublebut you need anintfor your index, so you'll have to convert the result. See How do I generate a random int number in C#? for more.
int randomIndex = myRandom.Next(0, lines.Length);
For now I'll leave it there or I'd be giving you the full solution. If you have issues though, please post new questions here with what you've tried so far, and why it's not working (i.e. are you getting an error message, if so what, or is it doing something different to what you'd expect).
You used Console.WriteLine, how could i just write it to label?
– Dziu Gas
Nov 13 '18 at 17:27
string lines = Label.Text?
– Dziu Gas
Nov 13 '18 at 17:36
Close.... The left side of the equals is the assignee, the right side is the value to be assigned. Try searching this site or Google for clues initially, then post back if stuck. E.g. stackoverflow.com/questions/10704020/…
– JohnLBevan
Nov 13 '18 at 18:10
Ehh, i dont understand
– Dziu Gas
Nov 13 '18 at 18:22
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53283930%2fneed-to-convert-code-for-pick-random-line-and-display%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Here are the pieces you need to solve this
- A Program. Below is the boilerplate code for a C# console application. Why's this needed? So your line of code has some context to run in. NB: You could run code via LinqPad without this, or you could use a different type of project to host your code; but for now I'm keeping things simple.
using System;
public class Program
{
public static void Main()
{
Console.WriteLine("Hello World");
}
}
- An array holding the strings you want to display. See Options for initializing a string array for additional info / options:
string lines = new {
"Locating the required gigapixels to render...",
"Spinning up the hamster...",
"Shovelling coal into the server...",
"Programming the flux capacitor"
);
- A way to pick one of these strings at random. You get a string from the array by putting a number (the index) in square brackets after the variable name, with each item in the array having consecutive numbers starting at 0. ; e.g.
lines[1]would give you the string"Spinning up the hamster...". You can get a random number using an instanceRandomclass'sNextmethod. This method requires you to provide parameters to define the range in which the result should fall. The method returns adoublebut you need anintfor your index, so you'll have to convert the result. See How do I generate a random int number in C#? for more.
int randomIndex = myRandom.Next(0, lines.Length);
For now I'll leave it there or I'd be giving you the full solution. If you have issues though, please post new questions here with what you've tried so far, and why it's not working (i.e. are you getting an error message, if so what, or is it doing something different to what you'd expect).
You used Console.WriteLine, how could i just write it to label?
– Dziu Gas
Nov 13 '18 at 17:27
string lines = Label.Text?
– Dziu Gas
Nov 13 '18 at 17:36
Close.... The left side of the equals is the assignee, the right side is the value to be assigned. Try searching this site or Google for clues initially, then post back if stuck. E.g. stackoverflow.com/questions/10704020/…
– JohnLBevan
Nov 13 '18 at 18:10
Ehh, i dont understand
– Dziu Gas
Nov 13 '18 at 18:22
add a comment |
Here are the pieces you need to solve this
- A Program. Below is the boilerplate code for a C# console application. Why's this needed? So your line of code has some context to run in. NB: You could run code via LinqPad without this, or you could use a different type of project to host your code; but for now I'm keeping things simple.
using System;
public class Program
{
public static void Main()
{
Console.WriteLine("Hello World");
}
}
- An array holding the strings you want to display. See Options for initializing a string array for additional info / options:
string lines = new {
"Locating the required gigapixels to render...",
"Spinning up the hamster...",
"Shovelling coal into the server...",
"Programming the flux capacitor"
);
- A way to pick one of these strings at random. You get a string from the array by putting a number (the index) in square brackets after the variable name, with each item in the array having consecutive numbers starting at 0. ; e.g.
lines[1]would give you the string"Spinning up the hamster...". You can get a random number using an instanceRandomclass'sNextmethod. This method requires you to provide parameters to define the range in which the result should fall. The method returns adoublebut you need anintfor your index, so you'll have to convert the result. See How do I generate a random int number in C#? for more.
int randomIndex = myRandom.Next(0, lines.Length);
For now I'll leave it there or I'd be giving you the full solution. If you have issues though, please post new questions here with what you've tried so far, and why it's not working (i.e. are you getting an error message, if so what, or is it doing something different to what you'd expect).
You used Console.WriteLine, how could i just write it to label?
– Dziu Gas
Nov 13 '18 at 17:27
string lines = Label.Text?
– Dziu Gas
Nov 13 '18 at 17:36
Close.... The left side of the equals is the assignee, the right side is the value to be assigned. Try searching this site or Google for clues initially, then post back if stuck. E.g. stackoverflow.com/questions/10704020/…
– JohnLBevan
Nov 13 '18 at 18:10
Ehh, i dont understand
– Dziu Gas
Nov 13 '18 at 18:22
add a comment |
Here are the pieces you need to solve this
- A Program. Below is the boilerplate code for a C# console application. Why's this needed? So your line of code has some context to run in. NB: You could run code via LinqPad without this, or you could use a different type of project to host your code; but for now I'm keeping things simple.
using System;
public class Program
{
public static void Main()
{
Console.WriteLine("Hello World");
}
}
- An array holding the strings you want to display. See Options for initializing a string array for additional info / options:
string lines = new {
"Locating the required gigapixels to render...",
"Spinning up the hamster...",
"Shovelling coal into the server...",
"Programming the flux capacitor"
);
- A way to pick one of these strings at random. You get a string from the array by putting a number (the index) in square brackets after the variable name, with each item in the array having consecutive numbers starting at 0. ; e.g.
lines[1]would give you the string"Spinning up the hamster...". You can get a random number using an instanceRandomclass'sNextmethod. This method requires you to provide parameters to define the range in which the result should fall. The method returns adoublebut you need anintfor your index, so you'll have to convert the result. See How do I generate a random int number in C#? for more.
int randomIndex = myRandom.Next(0, lines.Length);
For now I'll leave it there or I'd be giving you the full solution. If you have issues though, please post new questions here with what you've tried so far, and why it's not working (i.e. are you getting an error message, if so what, or is it doing something different to what you'd expect).
Here are the pieces you need to solve this
- A Program. Below is the boilerplate code for a C# console application. Why's this needed? So your line of code has some context to run in. NB: You could run code via LinqPad without this, or you could use a different type of project to host your code; but for now I'm keeping things simple.
using System;
public class Program
{
public static void Main()
{
Console.WriteLine("Hello World");
}
}
- An array holding the strings you want to display. See Options for initializing a string array for additional info / options:
string lines = new {
"Locating the required gigapixels to render...",
"Spinning up the hamster...",
"Shovelling coal into the server...",
"Programming the flux capacitor"
);
- A way to pick one of these strings at random. You get a string from the array by putting a number (the index) in square brackets after the variable name, with each item in the array having consecutive numbers starting at 0. ; e.g.
lines[1]would give you the string"Spinning up the hamster...". You can get a random number using an instanceRandomclass'sNextmethod. This method requires you to provide parameters to define the range in which the result should fall. The method returns adoublebut you need anintfor your index, so you'll have to convert the result. See How do I generate a random int number in C#? for more.
int randomIndex = myRandom.Next(0, lines.Length);
For now I'll leave it there or I'd be giving you the full solution. If you have issues though, please post new questions here with what you've tried so far, and why it's not working (i.e. are you getting an error message, if so what, or is it doing something different to what you'd expect).
answered Nov 13 '18 at 16:21
JohnLBevanJohnLBevan
14.4k145105
14.4k145105
You used Console.WriteLine, how could i just write it to label?
– Dziu Gas
Nov 13 '18 at 17:27
string lines = Label.Text?
– Dziu Gas
Nov 13 '18 at 17:36
Close.... The left side of the equals is the assignee, the right side is the value to be assigned. Try searching this site or Google for clues initially, then post back if stuck. E.g. stackoverflow.com/questions/10704020/…
– JohnLBevan
Nov 13 '18 at 18:10
Ehh, i dont understand
– Dziu Gas
Nov 13 '18 at 18:22
add a comment |
You used Console.WriteLine, how could i just write it to label?
– Dziu Gas
Nov 13 '18 at 17:27
string lines = Label.Text?
– Dziu Gas
Nov 13 '18 at 17:36
Close.... The left side of the equals is the assignee, the right side is the value to be assigned. Try searching this site or Google for clues initially, then post back if stuck. E.g. stackoverflow.com/questions/10704020/…
– JohnLBevan
Nov 13 '18 at 18:10
Ehh, i dont understand
– Dziu Gas
Nov 13 '18 at 18:22
You used Console.WriteLine, how could i just write it to label?
– Dziu Gas
Nov 13 '18 at 17:27
You used Console.WriteLine, how could i just write it to label?
– Dziu Gas
Nov 13 '18 at 17:27
string lines = Label.Text?
– Dziu Gas
Nov 13 '18 at 17:36
string lines = Label.Text?
– Dziu Gas
Nov 13 '18 at 17:36
Close.... The left side of the equals is the assignee, the right side is the value to be assigned. Try searching this site or Google for clues initially, then post back if stuck. E.g. stackoverflow.com/questions/10704020/…
– JohnLBevan
Nov 13 '18 at 18:10
Close.... The left side of the equals is the assignee, the right side is the value to be assigned. Try searching this site or Google for clues initially, then post back if stuck. E.g. stackoverflow.com/questions/10704020/…
– JohnLBevan
Nov 13 '18 at 18:10
Ehh, i dont understand
– Dziu Gas
Nov 13 '18 at 18:22
Ehh, i dont understand
– Dziu Gas
Nov 13 '18 at 18:22
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53283930%2fneed-to-convert-code-for-pick-random-line-and-display%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
Welcome to Stack Overflow! You seem to be asking for someone to write some code for you. Stack Overflow is a question and answer site, not a code-writing service. Please see here to learn how to write effective questions.
– Arthur Attout
Nov 13 '18 at 15:11
2
Possible duplicate of Pick Random String from Array
– Amy
Nov 13 '18 at 15:18
2
I guess people expect you to learn the basics of c# before asking questions... Otherwise you'll have a hard time understanding the answers and do modifications to them to fit your needs.
– Oram
Nov 13 '18 at 15:27
1
Hi there, the thing you are trying to do can be achieved. quite easily. But, to use the C# language more efficiently, spend some time in MSDN for conceptualization. I am sure that will help you a lot :)
– Tazbir Bhuiyan
Nov 13 '18 at 15:27
2
If you want someone to write you some code there are paid platforms for that.. this is a Q&A site
– Maor Refaeli
Nov 13 '18 at 15:43