.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Post New Web Links

Finding an array index by giving a maximum value

Posted By:      Posted Date: May 22, 2011    Points: 0   Category :JQuery

Hi there,

.Net 4.0 C#

1) I have an int Array {5, 10, 1, 40, 110, 120, 12, 70}
2) I have an external number ie. 44

Without using loops, is there a possibility to find the index of the highest value in the array that must be lower or equal than the external number (in this case 40, or index 3)?

thx in adv.


View Complete Post

More Related Resource Links

Index was outside the bounds of the array.

hi..i create registration form in asp.net & sql server..after fill up form when i click save button it's show error..here is my code :-private void ExecuteInsert(string AccNo, string CompanyName, string Desc2, string RegisterNo, string Address1, string Address2, string Address3, string Address4, string PostCode, string DeliverAddr1, string DeliverAddr2, string DeliverAddr3, string DeliverAddr4, string DeliverPostCode, string Attention, string Phone1, string Phone2, string Fax1, string Fax2, string AreaCode, string SalesAgent, string DebtorType, string NatureOfBusiness, string WebURL, string EmailAddress, string DisplayTerm, string UDF_Shipvia, string UDF_freigh, string UDF_SourceIn, string UDF_ProductEnq, string CurrencyCode)    {        SqlConnection conn = new SqlConnection(GetConnectionString());        string sql ="INSERT INTO Debtor (AccNo, CompanyName, Desc2, RegisterNo, Address1, Address2, Address3, Address4, PostCode, CreditLimit, CurrencyCode, DeliverAddr1, DeliverAddr2, DeliverAddr3, DeliverAddr4, DeliverPostCode, Attention, Phone1, Phone2, Fax1, Fax2, AreaCode, SalesAgent, DebtorType, NatureOfBusiness, WebURL, EmailAddress, DisplayTerm, UDF_Shipvia, UDF_freigh, UDF_ProductEnq, UDF_SourceIn) VALUES " + " (@AccNo, @CompanyName, @Desc2, @RegisterNo, @Address1, @Ad

there are some problem in finding the index of listview


how we find the listview index of row in case of item databind

The maximum array length quota (16384) has been exceeded while reading XML data.



I am getting this error when I try to send a message to my service. I have updated the ReaderQuotas on both the client and the server. Is there something else that I need to do to get the service to accept the message?



What's the Realistic Maximum Number of Index per Table


What is a good real world maximum(so i am not looking for this answer:http://blog.sqlauthority.com/2009/06/29/sql-server-maximum-number-of-index-per-table/) for the number of indexes on a table (table has around 50 columns and at the moment 3 indexes)

. I would like to add 3 more indexes on fields that are not used for joining but are searched upon lots of the time. Is this a good idea?

Index was outside the bounds of the array.


why I am getting this error when trying to run the application with no argument although I set the if function? how can I solve it plz?


static void Main(string[] args)
  Control.CheckForIllegalCrossThreadCalls = false;

  if (args[0] == null)
    Application.Run(new frmSplash());
    Application.Run(new frmMain());

Jassim Rahma

Sort Array along with its Corresponding index



  I have a one-d Array named zz containing {5,3,8,1,9,6}. Current order of indices of the elements is : 0,1,2,3,4,5. 

Now I want to sort the array z in ascending order in such a way that its corresponding indices also sort according to its respective elements.

Ex: Elts in Ascending order : 1,3,5,6,8,9

and Respective indices will be : 3,1,0,5,2,4.

Another Ex: What "Additions" should i make to the following code, if the Array Element repeats ??  Epected Oreder of Indices : 1,0,4,3,2

int[] A = new int[6] { 3, 2, 8, 5, 3 };  //{ 5, 3, 8, 1, 9, 6 };
            int[] B = new int[6];
            int[] index = new int[6];
            int flag = 0;
            Console.WriteLine("Array A:");
            for (int i = 0; i < A.Length; i++)

Super Urgent!!Index was outside the bounds of the array


Hi. I am having problem uploading the textfile. It will appear this error. When i upload other files,it is working fine. Could the reason be because the file that i am trying to upload has around 100 columm? Thanks for ur help. Could you paste the code too?

This is the error:

Index was outside the bounds of the array.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IndexOutOfRangeException: Index was outside the bounds of the array.

Source Error:

Line 142:        'for loop from 0 to total header element - 1
Line 143: For i As Integer = 0 To preheader.Length - 1 Step 1
Line 144: Dim header1 As String = preheader(i) & trgheader(i) 'header1 = joins up start header and trailin header
Line 145: Dim header2 As String = preheader(i) & " " & trgheader(i) 'header2 = joins up start header

Finding Rows in ADO.NET

ADO.NET implements three basic forms to locate Rows - The Find method as applied to the Rows collection, the Find method as applied to the DataView object and the Contains method as applied to the Rows collection.

DataRowCollection Find and Contains Method

The DataRowCollection is a major component of the DataTable. While the DataColumnCollection defines the schema of the table, the DataRowCollection contains the actual data for the table, where each DataRow in the DataRowCollection represents a single row.

You can call the Add and Remove methods to insert and delete DataRow objects from the DataRowCollection. You can also call the Find method to search for DataRow objects that contain specific values in primary key columns, and the Contains method to search character-based data for single words or phrases.

DataView Find and FindRows Method

Using the Find and FindRows methods of the DataView, you can search for rows according to their sort key values. The case-sensitivity of search values in the Find and FindRows methods is determined by the CaseSensitive property of the underlying DataTable. Search values must match existing sort key values in their entirety in order to return a result.

Finding username


Im running a query where it selects a property from the user with the matching username but i dont know how to find out the username of the currently loggedin user.

Please Help!

Binding an array to dropdown list


I have the following string which is a list of urls. How do I get this to work so the url shows for the selection and also is the value?      


allLinks = newAllLinks
        Me.DropDownList1.DataTextField = "Link"
        Me.DropDownList1.DataValueField = "LinkURL"
        Me.DropDownList1.Items.Insert(0, New ListItem(" - Select - ", 0))
        Me.DropDownList1.DataSource = allLinks


 ArgumentNullException: Value cannot be null.
Parameter name: container]
   System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName) +121
   System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName, String format) +8

how to get an array of all the asp.net textbox control inside create user wizard control?



How can I get all the textboxes inside a create user wizard control using getElementsByTagName().

Below is my JQuery code:

<script type="text/javascript">
        function addLoadEvent(func) {
            var oldonload = window.onload;
            if (typeof window.onload != 'function') {
                window.onload = func;
            } else {
                window.onload = function() {

        function prepareInputsForHints() {
            var inputs = document.getElementsByTagName("asp:TextBox");
            for (var i = 0; i < inputs.length; i++) {
                inputs[i].onfocus = function() {
                    this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
                inputs[i].onblur = function() {
                    this.parentNode.getElementsByTagName("span")[0].style.display = "none";



<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>

How to cast integer values as an array of enum values?


Hello all!

I'm working with VS2010 Beta2, ASP.NET and Dynamic Data. I'm using VB but will certainly be happy to receive a C# example if necessary. Laughing

I used a few of Steve's examples (Writing Attributes and Extension Methods for Dynamic Data and Dynamic Data - Hiding Columns in selected PageTemplates) to create a custom property attribute to be applied to a dynamic data column and want it to accept an array of enum values (each value will represent a dynamic data page template where this column should not be displayed).  My new attribute works fine when I hardcode it like this, meaning the HideColumnIn attribute is properly populated with the array of enum values:

<HideColumnIn(PageTemplate.List, PageTemplate.Edit)> _
Public Property My_DD_Column As Object


However, I want to store the values to be used for the HideColumnIn in the DB as integer values that correspond to the

Unity - Inject array



I have the following in the config file...

container.RegisterType<ProductInstanceValidatorBase, CartItemStockValidator>();
container.RegisterType<ProductInstanceValidatorBase, MonthlyCartItemValidator>();

..constructor like so...

 public CartValidator(ProductInstanceValidatorBase[] validators)
   this.validators = validators;

...I call the following but the array is empty...


Any ideas?

Cheers, WT.



Converting ReportDocument object into byte array ?


Hi All,

          Is it possible to convert the Report Document object as a byte array and store it in SQL , later retrieve and assing it to a report ?


Invalid length for a Base-64 char array for my coding in ASP.net C#. How to solve it ?


Hi Friends ,

I have done encrypted password and decode but i got error  like  this  " Invalid length for a Base-64 char array" .

Pls help . Thanks


psswd = txtPassword.Text;

pwed = base64Decode(psswd);

public string base64Decode(string sData)
            System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
            System.Text.Decoder utf8Decode = encoder.GetDecoder();
            byte[] todecode_byte = Convert.FromBase64String(sData);
            int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
            char[] decoded_char = new char[charCount];
            utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
            string result = new String(decoded_char); return result;

'Value' should be between 'minimum' and 'maximum'.


I'm attempting to invoke with parameters:


Dim thing2 As New mydelsubPBStep(AddressOf pbStep)

Me.Invoke(thing2, "setMax", dt.Rows.Count)      <---- this is where the error occurs


the delegate looks like this:

Private Delegate

Class which contains an array of objects of type "Class2"



1  Partial Class _Default
2  Inherits System.Web.UI.Page

3 Public Function Ohjoy(ByVal X As Integer) As Integer
4 Dim theClass As New Class1 '= New Class1()
5    theClass.ReSize(0)
6    theClass.myBaby(0).GetName(0) = "Hello" 'Property Chars is read only'
7    Return 1
8 End Function
I have a first class named "Class1". I have a second class named "Class2" Class2, is a member of class 1,
and is implemented as an array of objects of type Class 2.

If I try and call the Accessor GetName() my hard coded value "Hello" in my accessor is not returned? Only
an alpha character like "T"

Also if I try and assigne a value using the setter GetName() it does not work, and the compiler gives me
an error message "property Chars is ReadOnly? Does anyone know what is wrong in my code? Line 6 above


Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
End Sub
End Class

Public Class Class1
    Dim bs As Integer
    Public myBaby() As Class2
    Public myB As Class2
    Public Function ReSize(By

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend