Click here to Skip to main content
15,889,281 members
Home / Discussions / C#
   

C#

 
GeneralRe: saving a Word Doc from address bar in .net/C# Pin
DerekT-P25-Jul-20 9:22
professionalDerekT-P25-Jul-20 9:22 
GeneralRe: saving a Word Doc from address bar in .net/C# Pin
Gerry Schmitz25-Jul-20 9:58
mveGerry Schmitz25-Jul-20 9:58 
GeneralRe: saving a Word Doc from address bar in .net/C# Pin
DerekT-P25-Jul-20 11:38
professionalDerekT-P25-Jul-20 11:38 
AnswerRe: saving a Word Doc from address bar in .net/C# Pin
Richard MacCutchan25-Jul-20 21:59
mveRichard MacCutchan25-Jul-20 21:59 
GeneralRe: saving a Word Doc from address bar in .net/C# Pin
Pita3226-Jul-20 6:37
Pita3226-Jul-20 6:37 
GeneralRe: saving a Word Doc from address bar in .net/C# Pin
Richard MacCutchan26-Jul-20 6:46
mveRichard MacCutchan26-Jul-20 6:46 
GeneralRe: saving a Word Doc from address bar in .net/C# Pin
Richard Deeming26-Jul-20 23:50
mveRichard Deeming26-Jul-20 23:50 
GeneralRe: saving a Word Doc from address bar in .net/C# Pin
Richard MacCutchan27-Jul-20 0:03
mveRichard MacCutchan27-Jul-20 0:03 
AnswerRe: saving a Word Doc from address bar in .net/C# Pin
Richard Deeming26-Jul-20 23:51
mveRichard Deeming26-Jul-20 23:51 
QuestionGet List Of SQL Foreign Keys Using C# Pin
Kevin Marois24-Jul-20 6:46
professionalKevin Marois24-Jul-20 6:46 
AnswerRe: Get List Of SQL Foreign Keys Using C# Pin
Richard Deeming24-Jul-20 7:29
mveRichard Deeming24-Jul-20 7:29 
GeneralRe: Get List Of SQL Foreign Keys Using C# Pin
Kevin Marois24-Jul-20 7:42
professionalKevin Marois24-Jul-20 7:42 
GeneralRe: Get List Of SQL Foreign Keys Using C# Pin
Dave Kreskowiak24-Jul-20 7:49
mveDave Kreskowiak24-Jul-20 7:49 
GeneralRe: Get List Of SQL Foreign Keys Using C# Pin
Kevin Marois24-Jul-20 7:53
professionalKevin Marois24-Jul-20 7:53 
GeneralRe: Get List Of SQL Foreign Keys Using C# Pin
Kevin Marois24-Jul-20 7:53
professionalKevin Marois24-Jul-20 7:53 
GeneralRe: Get List Of SQL Foreign Keys Using C# Pin
OriginalGriff24-Jul-20 7:50
mveOriginalGriff24-Jul-20 7:50 
GeneralRe: Get List Of SQL Foreign Keys Using C# Pin
Kevin Marois24-Jul-20 7:53
professionalKevin Marois24-Jul-20 7:53 
QuestionWhat's the most easy-to-read way of initializing a string-int-pair array? Pin
arnold_w23-Jul-20 21:56
arnold_w23-Jul-20 21:56 
Let's assume I have a simple class:
C#
public class StringAndInt
{
    public string myString;
    public int myInt;
    public StringAndInt(string myString, int myInt)
    {
        this.myString = myString;
        this.myInt = myInt;
    }
}
If I want to create an array of this class, then the code pretty quickly becomes hard to read:
C#
StringAndInt[] myArray = new StringAndInt[] { new StringAndInt("String", 0), new StringAndInt("String", 1), new StringAndInt("String", 2) };
I think in C-programming the corresponding code is much easier to read:
C++
StringAndInt myArray[] = {{"String", 0}, {"String", 1}, {"String", 2}};
What's the most readable way I can accomplish this in C#? Please note that I need to be able to create arrays of different sizes, but in practice it would be ok to set an upper limit of 1000 elements. I could create lots of methods like below, but then I would like to be able to tell the compiler to optimize away unused methods (I'm not using reflection and I don't export the code as a dll to anybody so it would be safe to optimize away uncalled methods):
C#
StringAndInt[] constructArray(string myString, int myInt)
{
    return new StringAndInt[] { new StringAndInt(myString, myInt) };
}

StringAndInt[] constructArray(string myString0, int myInt0, string myString1, int myInt1)
{
    return new StringAndInt[] { new StringAndInt(myString0, myInt0), new StringAndInt(myString1, myInt1) };
}

StringAndInt[] constructArray(string myString0, int myInt0, string myString1, int myInt1, string myString2, int myInt2)
{
    return new StringAndInt[] { new StringAndInt(myString0, myInt0), new StringAndInt(myString1, myInt1), new StringAndInt(myString2, myInt2) };
}
.
.
.
StringAndInt[] myArray = constructArray("String", 0, "String", 1, "String", 2);

AnswerRe: What's the most easy-to-read way of initializing a string-int-pair array? Pin
OriginalGriff23-Jul-20 22:18
mveOriginalGriff23-Jul-20 22:18 
AnswerRe: What's the most easy-to-read way of initializing a string-int-pair array? Pin
Richard MacCutchan23-Jul-20 22:22
mveRichard MacCutchan23-Jul-20 22:22 
AnswerRe: What's the most easy-to-read way of initializing a string-int-pair array? Pin
Richard Deeming23-Jul-20 22:39
mveRichard Deeming23-Jul-20 22:39 
GeneralRe: What's the most easy-to-read way of initializing a string-int-pair array? Pin
jsc4224-Jul-20 3:17
professionaljsc4224-Jul-20 3:17 
AnswerRe: What's the most easy-to-read way of initializing a string-int-pair array? Pin
Gerry Schmitz25-Jul-20 7:30
mveGerry Schmitz25-Jul-20 7:30 
AnswerRe: What's the most easy-to-read way of initializing a string-int-pair array? Pin
BillWoodruff27-Jul-20 17:25
professionalBillWoodruff27-Jul-20 17:25 
QuestionHow to convert C++ 2005 project to 2016 Pin
Sheryl Brock23-Jul-20 4:14
Sheryl Brock23-Jul-20 4:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.