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 Json file in string (for example):
#{
"Url": "http://site.com/?q=windows8"
}
How can i take the information after ?q= on c# (windows 8). Sorry for my English.
You can use the querystring.
in Codebehind file
public String q
{
get
{
if (Request.QueryString["q"] == null)
return String.Empty;
return Convert.ToString(Request.QueryString["q"]);
}
}
then use the line below to get the value
var index = ('<%=q%>');
You can do simply this :
string s = "myURL/?q=windows8";
// Loop through all instances of ?q=
int i = 0;
while ((i = s.IndexOf("?q=", i)) != -1)
{
// Print out the substring. Here : windows8
Console.WriteLine(s.Substring(i));
// Increment the index.
i++;
}
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
This post was edited and submitted for review 1 year ago and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
I have a method that needs to convert a string to the generic type:
T GetValue<T>(string name)
{
string item = getstuff(name);
return item converted to T // ????????
}
T could be int or date.
you can use Convert.ChangeType
T GetValue<T>(string name)
{
string item = getstuff(name);
return (T)Convert.ChangeType(item, typeof(T));
}
if you need to limit input types only for int and DateTime, add condition like below
if (typeof(T) != typeof(int) && typeof(T) != typeof(DateTime))
{
// do something with other types
}
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 can I convert the following logic to LINQ?
Flaggedlist is a type of List<string>. request.flagged is a numeric value in a request POCO.
if (request.Flagged == 1)
{
if (!patient.UserFlaggedList.Contains(request.UserId))
{
flaggedList.Add(request.UserId);
}
}
else if (request.Flagged == 0)
{
string usrid = flaggedList.Where(a => a == request.UserId).FirstOrDefault<string>();
flaggedList.Remove(usrid);
}
It can be boiled down to two simple IF statements and the 2nd part shortened further still:
if (request.Flagged == 1 && !patient.UserFlaggedList.Contains(request.UserId))
flaggedList.Add(request.UserId);
if (request.Flagged == 0)
flaggedList.Remove(flaggedList.FirstOrDefault(a => a == request.UserId));
This is pretty condensed and clear, not sure why you'd want to make it more condensed.
If you really want to make it shorter, maybe you can do this:
if (request.Flagged == 1 && !patient.UserFlaggedList.Contains(request.UserId))
{
flaggedList.Add(request.UserId);
}
else if (request.Flagged == 0)
{
flaggedList.Remove(flaggedList.Where(a => a == request.UserId).FirstOrDefault<string>());
}
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 stuck in a problem.
I have a class :
public class CustomerViewModel
{
public string Name;
public string[][] values;
public bool[] flag;
}
I wish to get count of rows in values[][] where row !=null
Assuming you already have:
var vm = new CustomerViewModel();
And have populated the values array, then..
For a count of non-null rows try:
var count = vm.values.Count(i => i != null);
Or for all rows where values[row][0] is not null:
var count = vm.values.Count(i => i != null && i.Length > 0 && i[0] != null);
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
class abc
{
public object test(params object[] par)
{
//I need Count of the parameter here which means to check par contains 1 or 1,2
}
}
I access the class like,
abc obj =new abc();
obj.test(1);
(or)
obj.test(1,2);
my question is, there is possible to send 1 or 1,2 .I need the count of the How many parameters are in the Object in test class?How to do this?
Use Array.Length property.
public object test(params object[] par)
{
var count = par == null ? 0 : par.Length;
}
You can use Length property of object array.
public object test(params object[] par)
{
int length = par == null ? 0 : par.Length;
}
You can use Length property
Try This:
int len=par.Length;
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
Trying to put an integer data from database(Linq to sql) into a label getting this error exception:
left-hand side of an assignment must be a variable property or
indexer
Code:
protected void Page_Load(object sender, EventArgs e)
{
DataClassesDataContext data = new DataClassesDataContext();
var visit = (from v in data.SeeSites where v.Date == todaydate select v).FirstOrDefault();
int seennow = visit.See; // On This line I can put data in seenow variable, no problem
Convert.ToInt64(lblSeeNow.Text) = visit.See; // exception error appears here
}
Try:
if (visit.See != null) {
lblSeeNow.Text = visit.See.ToString();
}
You cannot assign something to a function result. In your case lblSeeNow.Text is of type String hence usage of ToString(); method of your Int value.
You need to use
lblSeeNow.Text = visit.See.ToString();
Convert.ToInt64(lblSeeNow.Text) = visit.See;
As you mentioned, this is the issue.
Convert.ToInt64 is a method. But you're trying to save a value to it.
You can't.
Just do this
lblSeeNow.Text = visit.See.ToString();
I think you want
lblSeeNow.Text = visit.See.ToString();
You can't assign anything to
Convert.ToInt64(lblSeeNow.Text)
because it evaluates to a number.
Convert.ToInt64(lblSeeNow.Text) isn't a variable. It takes the value in lblSeeNow.Text and converts it to a long. There isn't a variable to store stuff in anymore.
You probably want this:
lblSeeeNow.Text = visit.See.ToString();
You should convert the integer to string, also add a check for being sure that visit is not null
lblSeeNow.Text = visit != null ? visit.See.ToString() : string.Empty