छात्रवृत्ति फॉर्म में त्रुटि, कृपया मेरी समस्या का समाधान करें


System.ArgumentOutOfRangeException: Index and length must refer to a location within the string. Parameter name: length at System.String.Substring(Int32 startIndex, Int32 length) at ScholarFormDetail1112122.btn_submit_Click(Object sender, EventArgs e)

मैंने क्या प्रयास किया है:

System.ArgumentOutOfRangeException: Index and length must refer to a location within the string. Parameter name: length at System.String.Substring(Int32 startIndex, Int32 length) at ScholarFormDetail1112122.btn_submit_Click(Object sender, EventArgs e)

समाधान 1

निम्नलिखित उदाहरणों पर एक नज़र डालें:

public class Program
{
	public static void Main()
	{
		string test= "0123456789";
		
		// 1.) Will fail, because max. Index will be 9
		// string subString0= test.Substring(10, 1);
		
		// 2.) Ok
		string subString1= test.Substring(9, 1);
		
		// 3.) Will fail because  there is only one character available. See note *1)
		// string subString2= test.Substring(9, 100);

		// 4.) Ok
		string subString3= test.Substring(9, 1);
	}
}

नोट 1)
उस मामले में अपवाद फेंकना संदिग्ध है। अधिकांश अन्य भाषाएँ केवल उपलब्ध वर्ण लौटा देंगी।

[Edit]

नोट *1) , रिचर्ड को उसके संकेत के लिए धन्यवाद।
कुछ भाषाएँ उस मामले में अपवाद नहीं फेंकती हैं।

मुझे उम्मीद है यह मदद करेगा।

コメント

タイトルとURLをコピーしました