i tried to fill a variable in a loop foreach
<%@ Page language="c#" Codebehind="syncer.aspx.cs" AutoEventWireup="True" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Xml.Serialization" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.Runtime.Serialization.Json" %>
<%
String a;
a = Request.QueryString.Get("todo");
if(a=="sync"){
string url = Request.Url.GetLeftPart(UriPartial.Path);
Response.Write(url);
string strData = url;
char[] separator = new char[] { '/' };
string[] strSplitArr = strData.Split(separator);
string resser;
foreach (string arrStr in strSplitArr)
{
if(arrStr != "AssistAplDataBtrApplyTransport.aspx"){
resser += arrStr;
}else{
}
}
Response.Write(resser);
}else{
}
%>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Xml.Serialization" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.Runtime.Serialization.Json" %>
<%
String a;
a = Request.QueryString.Get("todo");
if(a=="sync"){
string url = Request.Url.GetLeftPart(UriPartial.Path);
Response.Write(url);
string strData = url;
char[] separator = new char[] { '/' };
string[] strSplitArr = strData.Split(separator);
string resser;
foreach (string arrStr in strSplitArr)
{
if(arrStr != "AssistAplDataBtrApplyTransport.aspx"){
resser += arrStr;
}else{
}
}
Response.Write(resser);
}else{
}
%>
but i get the following error:
Serverfehler in der Anwendung /WebService.
Kompilierungsfehler
Beschreibung: Fehler bei der Kompilierung einer Ressource, die zur Verarbeitung dieser Anforderung erforderlich ist. Überprüfen Sie die folgenden spezifischen Fehlerdetails, und ändern Sie den Quellcode entsprechend.
Compilerfehlermeldung: CS0165: Verwendung der nicht zugewiesenen lokalen Variablen resser
Where is my false?
Javeed M ShaikhPosted Apr 5, 2013, 10:35 AM
with the error message it looks like your local variable is not assigned a default value:
you code:
string resser;
change it to:
string resser = string.Empty;
try again and let us know.