This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 11 years ago.
foreach (string line in assigment_lines)
{
// Object reference not set to an instance of
chars.AddRange(line.Split('=')); object.
}
string[] strArray = chars.ToArray();
My program give me Null Reference Exception in above code what a problem ?
Make sure that line is not null also check where do you define chars array.
You can do something like this:
foreach (string line in assigment_lines)
{
if (!string.IsNullOrEmpty(line)) {
chars.AddRange(line.Split('=')); // Object reference not set to an instance of object.
}
}
string[] strArray = chars.ToArray();
Related
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I've been while out of C# and MVC. And I am really struggling with the following error, I really don't see it. I have a list of restrictions and i want to add their keys to an string[].
int cntr = 0;
//loop through restrictions and add to array
foreach (var Restriction in this.admingroupRepository.Context.AdminRestrictions.ToList())
{
currentRestrictionKeys[cntr] = Restriction.Key;
cntr += 1;
}
This is the error i get on the cntr += 1 line:
Index was outside the bounds of the array.
I don't understand where this comes from, the foreach breaks before the cntr is out of the array's bounds right?
You have allocated too little space for currentRestrictionKeys. But you don't really need to preallocate it at all; you can just use a trivial projection with LINQ:
var currentRestrictionKeys = this.admingroupRepository.Context.AdminRestrictions
.Select(r => r.Key)
.ToArray();
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I need to put a comma before the last char of a string.
For example:
Input: 101919 = Ouput: 10191,9
What is the best way to do that?
if (input.Length > 0) { input = input.Insert(input.Length - 1, ","); }
With the insert method
strTarget = strTarget.Insert( srtrTarget.Length -1, ",");
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
Here is my code :
XmlNodeList ProjectNode = DOC.GetElementsByTagName("AppBuilderProject");
foreach (XmlNode AllNodes in ProjectNode)
{
Project.Titel = AllNodes["Titel"].InnerText; // 1st value from node
foreach (XmlNode controlsform in Project.Forms) // arraylist Forms
{
Project.Forms = controlsform["forms"].InnerText;// error
}
}
Please tell me how to resolve this problem.
Property "Project.Forms" is obviously of type arraylist and property (XmlNode).InnerText is string
Try this
if(Project.Forms == null) Project.Forms = new ArrayList();
Project.Forms.Add(controlsform["forms"].InnerText);
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
So, what I am trying to do is iterate through an array of x values, and for each iteration, get the current text value of label "plabel" + x (the labels are all already created and named. I am relatively new to using reflection, but from what I've read the following should work:
PropertyInfo pI;
pI = this.GetType().GetProperty("plabel" + count + ".Text"); //count is the current iteration #
MessageBox.Show(pI.Name);
But this is throwing a runtime exception. Can somebody please show me the correct way of doing this?
Try something like this:
//Gets the label (includes private fields)
FieldInfo fi = this.GetType().GetField("plabel" + count,
BindingFlags.NonPublic | BindingFlags.Instance);
Label label = fi.GetValue(this) as Label;
if (label != null)
{
MessageBox.Show(label.Text);
}
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I have this piece of coding which is supposed to receive a URL as a string and this URL is supposed to be set as the Image Url :-
Heres the code
foreach (SPListItem item in oSpListCln)
{
if (item.Title.Equals("Rubicks"))
{
Title.Text = item.Title;
lblSyp.Text = item["Sypnosis"].ToString();
PicPic.ImageUrl = item["PicPic"].ToString();
}
}
The value of item["PicPic"] is http://www.froot.nl/wp-content/uploads/quick-brown-fox-froot.jpg,http://www.froot.nl/wp-content/uploads/quick-brown-fox-froot.jpg
This doesn't work is it cause I'm setting a string as a URL of an image cause when I hard coded the link it worked but when I set the link to a string and try, it doesn't. Does anyone know a way of how to do this?
Given that the returned string is comma-separated as you wrote in comments, you could do something like:
string[] urlParts = item["PicPic"].ToString().Split(',');
PicPic.ImageUrl = urlParts[0];