Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Sorry, I am EXTREMELY NEW to C#. I do not have much experience with code, so keep that in mind. I want to have my console application do something like this example:
Who is the best?
(Text be written here^)
IF the answer is tim, then write "Your right!"
If the answer is NOT tim, then write "Wrong!" and the code doews not advance until the word "tim" is put in
You can use Console.WriteLine to write out text, and Console.ReadLine() to read in the response from the user. A while loop can be used to keep looping until the reponse matches.
I totally agree with the other answers and comments, but for convenience here is the code
public class Program
{
public static void Main()
{
Console.WriteLine("Who is the best?");
var answer = Console.ReadLine();
if (answer.Equals("tim")){
Console.WriteLine("You're right!")
} else {
Console.WriteLine("Wrong!")
}
}
}
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
when using StreamReader in C# to load a txt file into a list, i assume that using a simple "If" the string's length is over a particular length, it will add it to the list. can anyone provide C# code for this? this IS homework, but it's NOT a C# class. the instructor would gladly provide this if i asked this specifically. thx.
the txt file is a dictionary of ~280,000 words, one per line. very simple move to turn into a list, but i'm wondering about getting words at least 2 characters long.
Just use LINQ to give you a subset.
List<string> lines = File.ReadLines(filename)
.Where(l => l.Length > specifiedWordLength)
.ToList();
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a typed dataset with a column called price, which is of string datatype. And I'm showing this via ultrgrid/datagrid
How can I show the price in number format.
For example: price ==123456
in the grid it should be like 12,354,56
Try this
var a = price.ToString("##,###,##");
Reference
Custom Numeric Format Strings!
Look at some of the related links to the right of the screen. Some of them even ask the same question as you !
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
How to write this in C#?
Intent intent = new Intent(Intent.ActionSendMultiple, Android.Provider.MediaStore.Images.Media.ExternalContentUri);
handler(intent);
....
void handler(Intent intent)
{
ArrayList<Uri> imageUris = intent.GetParcelableArrayListExtra(Intent.ExtraStream);
...
}
ArrayList is available is c# but it does not have a generic (<T>) form. ArrayList is a list of objects.
What you want is System.Collections.Generic.List<T>
EDIT : In response to comments, try this;
List<Uri> imageUris = new List<Uri>(intent.GetIntegerArrayListExtra(Intent.ExtraStream));
Easy, just use List<Uri>. It's also faster than ArrayList.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm working on a program and to avoid complication I need to parse a given string variable to be a DirectoryInfo.
I was wondering if it were possible to parse a string to a DirectoryInfo.
If it is, how does one go about doing that?
Thanks
DirectoryInfo di = new DirectoryInfo(string);
MSDN, linked above, provides you the exceptions in case the string is invalid. Note: this is NOT if the directory exists. MSDN also makes note of this in the Remarks. You must then do:
if(di.Exists)
Well, it's not parsing, but the constructor for DirectoryInfo takes the path as a string:
DirectoryInfo di = new DirectoryInfo(#"c:\MyDir");
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have the following path...
'X:\Projects\4604-Renovation\Unity\4604_02\Assets\Models\FullBuilding\Materials\'
I want to split it at the directory 'Assets' and end up with...
'Assets\Models\FullBuilding\Materials\'
The directory 'Assets' will not always be in the same place in the path. How can I do this? Thanks.
Lets say your string is
string completePath = "X:\Projects\4604-Renovation\Unity\4604_02\Assets\Models\FullBuilding\Materials\";
string subPath = completePath.subString(completePath.IndexOf(#"Assets\"));
Please note that if your path contains multiple instances of Assests it will substring from first instance of Asset.
you can use path.IndexOf, you can use the str.SubString(str.IndexOf("\assetse")), you can do alot of things. playing with string is kinda fun...
most of the things you want to do with strings you can find on google anyway