C# 从包含两种结果类型的数组返回结果

C# 从包含两种结果类型的数组返回结果,c#,arrays,winforms,C#,Arrays,Winforms,您好,我正在尝试重新运行名为ZverejnenyUcetType的数组类型,但问题是此数组可能包含两种类型:StandartniUcetType和nestandardinucetype 所以问题是当我尝试像这样返回数组时: string[] dic_vstup = new string[] { (line) }; RozhraniWSDL.InformaceOPlatciType[] dic_vystup; RozhraniWSDL.rozhr

您好,我正在尝试重新运行名为
ZverejnenyUcetType
的数组类型,但问题是此数组可能包含两种类型:
StandartniUcetType
nestandardinucetype

所以问题是当我尝试像这样返回数组时:

  string[] dic_vstup = new string[] { (line) };
            RozhraniWSDL.InformaceOPlatciType[] dic_vystup;
            RozhraniWSDL.rozhraniCRPDPH srv = new RozhraniWSDL.rozhraniCRPDPH();
            StatusType status = srv.getStatusNespolehlivyPlatce(dic_vstup, out dic_vystup);
            string abc = status.bezVypisuUctu.ToString();   // If it is already a string, then ToString not needed


            for (int i = 0; i < dic_vystup.Length; i++)
            {
                RozhraniWSDL.InformaceOPlatciType info = dic_vystup[i];


for (int x = 0; x <= 3; x++)
{   
    file2.WriteLine((((RozhraniWSDL.StandardniUcetType)(info.zverejneneUcty[x].Item)).cislo) + "-"

        + (((RozhraniWSDL.StandardniUcetType)(info.zverejneneUcty[x].Item)).cislo) + "/" 

        + (((RozhraniWSDL.StandardniUcetType)(info.zverejneneUcty[x].Item)).kodBanky));     
}}
if (info.zverejneneUcty[x].Item is RozhraniWSDL.StandardniUcetType) {
    ...
} else {
    ...
}
RozhraniWSDL.StandardniUcetType std = info.zverejneneUcty[x].Item as RozhraniWSDL.StandardniUcetType;
if (std != null) {
    ...
}
RozhraniWSDL.NestandardniUcetType nstd = info.zverejneneUcty[x].Item as RozhraniWSDL.NestandardniUcetType;
if (nstd != null) {
    ...
}
static void WriteToFile(RozhraniWSDL.StandardniUcetType std, StreamWriter file) {
    ...
}
static void WriteToFile(RozhraniWSDL.NestandardniUcetType nstd, StreamWriter file) {
    ...
}
// I'm making up the inner types, adapt this to your code
public abstract class UcetType
{
    public virtual object predcislo { get; set; }
    public virtual object cislo { get; set; }
    public virtual object kodBanky { get; set; }

    public virtual void WriteToFile(StreamWriter file) 
    { 
        // build the string and write it to the file
        // considering all properties
        // this acts as "default" for this type and all derived ones
    }
}

public class StandardniUcetType : UcetType
{
    // This will use the abstract as-is
    // with all 3 properties and the "default" WriteToFile() method
}

public class NestandardniUcetType : UcetType
{
    /// <summary>
    /// Attempting to use this will throw an exception
    /// </summary>
    public override object predcislo
    {
        get { throw new NotSupportedException(); }
        set { throw new NotSupportedException(); }
    }
    /// <summary>
    /// Attempting to use this will throw an exception
    /// </summary>
    public override object kodBanky
    {
        get { throw new NotSupportedException(); }
        set { throw new NotSupportedException(); }
    }

    // change the way WriteToFile behaves
    public override void WriteToFile(StreamWriter file)
    {
        // build the string and write it to the file
        // only considering 'cislo' property
    }
}

// Usage example, based on question
for (int i = 0; i < dic_vystup.Length; i++)
{
    RozhraniWSDL.InformaceOPlatciType info = dic_vystup[i];   

    // I assume "3" is the expected length of the array ? Change the for like this:
    for (int x = 0; x <= info.zverejneneUcty.Length; x++)
    {   
        //Delegate to the WriteToFile() method the task to build and write the line!
        info.zverejneneUcty[x].Item.WriteToFile(file2);
    }
}
string[]dic_vstup=新字符串[]{(行)};
RozhraniWSDL.InformaceOPlatciType[]dic_vystup;
RozhraniWSDL.rozhraniCRPDPH srv=新的RozhraniWSDL.rozhraniCRPDPH();
StatusType status=srv.getStatusNespolehlivyPlatce(dic_vtup,out dic_vystup);
字符串abc=status.bezVypisuUctu.ToString();//如果已经是字符串,则不需要ToString
对于(int i=0;i对于(int x=0;x,在数组上使用OfType扩展方法将筛选所需的类型

foreach (var item in info.zverejneneUcty.OfType<RozhraniWSDL.StandardniUcetType>())
{
  file2.WriteLine(item.predcislo + "-" + item.cislo + "-" + item.kodBanky);
}
foreach(info.zverejnenucty.OfType()中的变量项)
{
文件2.写线(item.predcislo+“-”+item.cislo+“-”+item.kodBanky);
}

在数组上使用OfType扩展方法将筛选您需要的类型

foreach (var item in info.zverejneneUcty.OfType<RozhraniWSDL.StandardniUcetType>())
{
  file2.WriteLine(item.predcislo + "-" + item.cislo + "-" + item.kodBanky);
}
foreach(info.zverejnenucty.OfType()中的变量项)
{
文件2.写线(item.predcislo+“-”+item.cislo+“-”+item.kodBanky);
}

如果数组有两种不同的类型,则可以添加
If
语句,如下所示:

  string[] dic_vstup = new string[] { (line) };
            RozhraniWSDL.InformaceOPlatciType[] dic_vystup;
            RozhraniWSDL.rozhraniCRPDPH srv = new RozhraniWSDL.rozhraniCRPDPH();
            StatusType status = srv.getStatusNespolehlivyPlatce(dic_vstup, out dic_vystup);
            string abc = status.bezVypisuUctu.ToString();   // If it is already a string, then ToString not needed


            for (int i = 0; i < dic_vystup.Length; i++)
            {
                RozhraniWSDL.InformaceOPlatciType info = dic_vystup[i];


for (int x = 0; x <= 3; x++)
{   
    file2.WriteLine((((RozhraniWSDL.StandardniUcetType)(info.zverejneneUcty[x].Item)).cislo) + "-"

        + (((RozhraniWSDL.StandardniUcetType)(info.zverejneneUcty[x].Item)).cislo) + "/" 

        + (((RozhraniWSDL.StandardniUcetType)(info.zverejneneUcty[x].Item)).kodBanky));     
}}
if (info.zverejneneUcty[x].Item is RozhraniWSDL.StandardniUcetType) {
    ...
} else {
    ...
}
RozhraniWSDL.StandardniUcetType std = info.zverejneneUcty[x].Item as RozhraniWSDL.StandardniUcetType;
if (std != null) {
    ...
}
RozhraniWSDL.NestandardniUcetType nstd = info.zverejneneUcty[x].Item as RozhraniWSDL.NestandardniUcetType;
if (nstd != null) {
    ...
}
static void WriteToFile(RozhraniWSDL.StandardniUcetType std, StreamWriter file) {
    ...
}
static void WriteToFile(RozhraniWSDL.NestandardniUcetType nstd, StreamWriter file) {
    ...
}
// I'm making up the inner types, adapt this to your code
public abstract class UcetType
{
    public virtual object predcislo { get; set; }
    public virtual object cislo { get; set; }
    public virtual object kodBanky { get; set; }

    public virtual void WriteToFile(StreamWriter file) 
    { 
        // build the string and write it to the file
        // considering all properties
        // this acts as "default" for this type and all derived ones
    }
}

public class StandardniUcetType : UcetType
{
    // This will use the abstract as-is
    // with all 3 properties and the "default" WriteToFile() method
}

public class NestandardniUcetType : UcetType
{
    /// <summary>
    /// Attempting to use this will throw an exception
    /// </summary>
    public override object predcislo
    {
        get { throw new NotSupportedException(); }
        set { throw new NotSupportedException(); }
    }
    /// <summary>
    /// Attempting to use this will throw an exception
    /// </summary>
    public override object kodBanky
    {
        get { throw new NotSupportedException(); }
        set { throw new NotSupportedException(); }
    }

    // change the way WriteToFile behaves
    public override void WriteToFile(StreamWriter file)
    {
        // build the string and write it to the file
        // only considering 'cislo' property
    }
}

// Usage example, based on question
for (int i = 0; i < dic_vystup.Length; i++)
{
    RozhraniWSDL.InformaceOPlatciType info = dic_vystup[i];   

    // I assume "3" is the expected length of the array ? Change the for like this:
    for (int x = 0; x <= info.zverejneneUcty.Length; x++)
    {   
        //Delegate to the WriteToFile() method the task to build and write the line!
        info.zverejneneUcty[x].Item.WriteToFile(file2);
    }
}
更好的方法是使用
as
操作符进行强制转换,如下所示:

  string[] dic_vstup = new string[] { (line) };
            RozhraniWSDL.InformaceOPlatciType[] dic_vystup;
            RozhraniWSDL.rozhraniCRPDPH srv = new RozhraniWSDL.rozhraniCRPDPH();
            StatusType status = srv.getStatusNespolehlivyPlatce(dic_vstup, out dic_vystup);
            string abc = status.bezVypisuUctu.ToString();   // If it is already a string, then ToString not needed


            for (int i = 0; i < dic_vystup.Length; i++)
            {
                RozhraniWSDL.InformaceOPlatciType info = dic_vystup[i];


for (int x = 0; x <= 3; x++)
{   
    file2.WriteLine((((RozhraniWSDL.StandardniUcetType)(info.zverejneneUcty[x].Item)).cislo) + "-"

        + (((RozhraniWSDL.StandardniUcetType)(info.zverejneneUcty[x].Item)).cislo) + "/" 

        + (((RozhraniWSDL.StandardniUcetType)(info.zverejneneUcty[x].Item)).kodBanky));     
}}
if (info.zverejneneUcty[x].Item is RozhraniWSDL.StandardniUcetType) {
    ...
} else {
    ...
}
RozhraniWSDL.StandardniUcetType std = info.zverejneneUcty[x].Item as RozhraniWSDL.StandardniUcetType;
if (std != null) {
    ...
}
RozhraniWSDL.NestandardniUcetType nstd = info.zverejneneUcty[x].Item as RozhraniWSDL.NestandardniUcetType;
if (nstd != null) {
    ...
}
static void WriteToFile(RozhraniWSDL.StandardniUcetType std, StreamWriter file) {
    ...
}
static void WriteToFile(RozhraniWSDL.NestandardniUcetType nstd, StreamWriter file) {
    ...
}
// I'm making up the inner types, adapt this to your code
public abstract class UcetType
{
    public virtual object predcislo { get; set; }
    public virtual object cislo { get; set; }
    public virtual object kodBanky { get; set; }

    public virtual void WriteToFile(StreamWriter file) 
    { 
        // build the string and write it to the file
        // considering all properties
        // this acts as "default" for this type and all derived ones
    }
}

public class StandardniUcetType : UcetType
{
    // This will use the abstract as-is
    // with all 3 properties and the "default" WriteToFile() method
}

public class NestandardniUcetType : UcetType
{
    /// <summary>
    /// Attempting to use this will throw an exception
    /// </summary>
    public override object predcislo
    {
        get { throw new NotSupportedException(); }
        set { throw new NotSupportedException(); }
    }
    /// <summary>
    /// Attempting to use this will throw an exception
    /// </summary>
    public override object kodBanky
    {
        get { throw new NotSupportedException(); }
        set { throw new NotSupportedException(); }
    }

    // change the way WriteToFile behaves
    public override void WriteToFile(StreamWriter file)
    {
        // build the string and write it to the file
        // only considering 'cislo' property
    }
}

// Usage example, based on question
for (int i = 0; i < dic_vystup.Length; i++)
{
    RozhraniWSDL.InformaceOPlatciType info = dic_vystup[i];   

    // I assume "3" is the expected length of the array ? Change the for like this:
    for (int x = 0; x <= info.zverejneneUcty.Length; x++)
    {   
        //Delegate to the WriteToFile() method the task to build and write the line!
        info.zverejneneUcty[x].Item.WriteToFile(file2);
    }
}
最后,一个非常好的方法是为这两种类型编写两个单独的方法,并使用
dynamic
执行分派

  string[] dic_vstup = new string[] { (line) };
            RozhraniWSDL.InformaceOPlatciType[] dic_vystup;
            RozhraniWSDL.rozhraniCRPDPH srv = new RozhraniWSDL.rozhraniCRPDPH();
            StatusType status = srv.getStatusNespolehlivyPlatce(dic_vstup, out dic_vystup);
            string abc = status.bezVypisuUctu.ToString();   // If it is already a string, then ToString not needed


            for (int i = 0; i < dic_vystup.Length; i++)
            {
                RozhraniWSDL.InformaceOPlatciType info = dic_vystup[i];


for (int x = 0; x <= 3; x++)
{   
    file2.WriteLine((((RozhraniWSDL.StandardniUcetType)(info.zverejneneUcty[x].Item)).cislo) + "-"

        + (((RozhraniWSDL.StandardniUcetType)(info.zverejneneUcty[x].Item)).cislo) + "/" 

        + (((RozhraniWSDL.StandardniUcetType)(info.zverejneneUcty[x].Item)).kodBanky));     
}}
if (info.zverejneneUcty[x].Item is RozhraniWSDL.StandardniUcetType) {
    ...
} else {
    ...
}
RozhraniWSDL.StandardniUcetType std = info.zverejneneUcty[x].Item as RozhraniWSDL.StandardniUcetType;
if (std != null) {
    ...
}
RozhraniWSDL.NestandardniUcetType nstd = info.zverejneneUcty[x].Item as RozhraniWSDL.NestandardniUcetType;
if (nstd != null) {
    ...
}
static void WriteToFile(RozhraniWSDL.StandardniUcetType std, StreamWriter file) {
    ...
}
static void WriteToFile(RozhraniWSDL.NestandardniUcetType nstd, StreamWriter file) {
    ...
}
// I'm making up the inner types, adapt this to your code
public abstract class UcetType
{
    public virtual object predcislo { get; set; }
    public virtual object cislo { get; set; }
    public virtual object kodBanky { get; set; }

    public virtual void WriteToFile(StreamWriter file) 
    { 
        // build the string and write it to the file
        // considering all properties
        // this acts as "default" for this type and all derived ones
    }
}

public class StandardniUcetType : UcetType
{
    // This will use the abstract as-is
    // with all 3 properties and the "default" WriteToFile() method
}

public class NestandardniUcetType : UcetType
{
    /// <summary>
    /// Attempting to use this will throw an exception
    /// </summary>
    public override object predcislo
    {
        get { throw new NotSupportedException(); }
        set { throw new NotSupportedException(); }
    }
    /// <summary>
    /// Attempting to use this will throw an exception
    /// </summary>
    public override object kodBanky
    {
        get { throw new NotSupportedException(); }
        set { throw new NotSupportedException(); }
    }

    // change the way WriteToFile behaves
    public override void WriteToFile(StreamWriter file)
    {
        // build the string and write it to the file
        // only considering 'cislo' property
    }
}

// Usage example, based on question
for (int i = 0; i < dic_vystup.Length; i++)
{
    RozhraniWSDL.InformaceOPlatciType info = dic_vystup[i];   

    // I assume "3" is the expected length of the array ? Change the for like this:
    for (int x = 0; x <= info.zverejneneUcty.Length; x++)
    {   
        //Delegate to the WriteToFile() method the task to build and write the line!
        info.zverejneneUcty[x].Item.WriteToFile(file2);
    }
}
现在按如下方式更改循环:

for (int x = 0; x <= 3; x++) {
    dynamic item = info.zverejneneUcty[x].Item;
    WriteToFile(item, file2); // <<== Magic
}

for(int x=0;x如果数组有两种不同的类型,可以添加
If
语句,如下所示:

  string[] dic_vstup = new string[] { (line) };
            RozhraniWSDL.InformaceOPlatciType[] dic_vystup;
            RozhraniWSDL.rozhraniCRPDPH srv = new RozhraniWSDL.rozhraniCRPDPH();
            StatusType status = srv.getStatusNespolehlivyPlatce(dic_vstup, out dic_vystup);
            string abc = status.bezVypisuUctu.ToString();   // If it is already a string, then ToString not needed


            for (int i = 0; i < dic_vystup.Length; i++)
            {
                RozhraniWSDL.InformaceOPlatciType info = dic_vystup[i];


for (int x = 0; x <= 3; x++)
{   
    file2.WriteLine((((RozhraniWSDL.StandardniUcetType)(info.zverejneneUcty[x].Item)).cislo) + "-"

        + (((RozhraniWSDL.StandardniUcetType)(info.zverejneneUcty[x].Item)).cislo) + "/" 

        + (((RozhraniWSDL.StandardniUcetType)(info.zverejneneUcty[x].Item)).kodBanky));     
}}
if (info.zverejneneUcty[x].Item is RozhraniWSDL.StandardniUcetType) {
    ...
} else {
    ...
}
RozhraniWSDL.StandardniUcetType std = info.zverejneneUcty[x].Item as RozhraniWSDL.StandardniUcetType;
if (std != null) {
    ...
}
RozhraniWSDL.NestandardniUcetType nstd = info.zverejneneUcty[x].Item as RozhraniWSDL.NestandardniUcetType;
if (nstd != null) {
    ...
}
static void WriteToFile(RozhraniWSDL.StandardniUcetType std, StreamWriter file) {
    ...
}
static void WriteToFile(RozhraniWSDL.NestandardniUcetType nstd, StreamWriter file) {
    ...
}
// I'm making up the inner types, adapt this to your code
public abstract class UcetType
{
    public virtual object predcislo { get; set; }
    public virtual object cislo { get; set; }
    public virtual object kodBanky { get; set; }

    public virtual void WriteToFile(StreamWriter file) 
    { 
        // build the string and write it to the file
        // considering all properties
        // this acts as "default" for this type and all derived ones
    }
}

public class StandardniUcetType : UcetType
{
    // This will use the abstract as-is
    // with all 3 properties and the "default" WriteToFile() method
}

public class NestandardniUcetType : UcetType
{
    /// <summary>
    /// Attempting to use this will throw an exception
    /// </summary>
    public override object predcislo
    {
        get { throw new NotSupportedException(); }
        set { throw new NotSupportedException(); }
    }
    /// <summary>
    /// Attempting to use this will throw an exception
    /// </summary>
    public override object kodBanky
    {
        get { throw new NotSupportedException(); }
        set { throw new NotSupportedException(); }
    }

    // change the way WriteToFile behaves
    public override void WriteToFile(StreamWriter file)
    {
        // build the string and write it to the file
        // only considering 'cislo' property
    }
}

// Usage example, based on question
for (int i = 0; i < dic_vystup.Length; i++)
{
    RozhraniWSDL.InformaceOPlatciType info = dic_vystup[i];   

    // I assume "3" is the expected length of the array ? Change the for like this:
    for (int x = 0; x <= info.zverejneneUcty.Length; x++)
    {   
        //Delegate to the WriteToFile() method the task to build and write the line!
        info.zverejneneUcty[x].Item.WriteToFile(file2);
    }
}
更好的方法是使用
as
操作符进行强制转换,如下所示:

  string[] dic_vstup = new string[] { (line) };
            RozhraniWSDL.InformaceOPlatciType[] dic_vystup;
            RozhraniWSDL.rozhraniCRPDPH srv = new RozhraniWSDL.rozhraniCRPDPH();
            StatusType status = srv.getStatusNespolehlivyPlatce(dic_vstup, out dic_vystup);
            string abc = status.bezVypisuUctu.ToString();   // If it is already a string, then ToString not needed


            for (int i = 0; i < dic_vystup.Length; i++)
            {
                RozhraniWSDL.InformaceOPlatciType info = dic_vystup[i];


for (int x = 0; x <= 3; x++)
{   
    file2.WriteLine((((RozhraniWSDL.StandardniUcetType)(info.zverejneneUcty[x].Item)).cislo) + "-"

        + (((RozhraniWSDL.StandardniUcetType)(info.zverejneneUcty[x].Item)).cislo) + "/" 

        + (((RozhraniWSDL.StandardniUcetType)(info.zverejneneUcty[x].Item)).kodBanky));     
}}
if (info.zverejneneUcty[x].Item is RozhraniWSDL.StandardniUcetType) {
    ...
} else {
    ...
}
RozhraniWSDL.StandardniUcetType std = info.zverejneneUcty[x].Item as RozhraniWSDL.StandardniUcetType;
if (std != null) {
    ...
}
RozhraniWSDL.NestandardniUcetType nstd = info.zverejneneUcty[x].Item as RozhraniWSDL.NestandardniUcetType;
if (nstd != null) {
    ...
}
static void WriteToFile(RozhraniWSDL.StandardniUcetType std, StreamWriter file) {
    ...
}
static void WriteToFile(RozhraniWSDL.NestandardniUcetType nstd, StreamWriter file) {
    ...
}
// I'm making up the inner types, adapt this to your code
public abstract class UcetType
{
    public virtual object predcislo { get; set; }
    public virtual object cislo { get; set; }
    public virtual object kodBanky { get; set; }

    public virtual void WriteToFile(StreamWriter file) 
    { 
        // build the string and write it to the file
        // considering all properties
        // this acts as "default" for this type and all derived ones
    }
}

public class StandardniUcetType : UcetType
{
    // This will use the abstract as-is
    // with all 3 properties and the "default" WriteToFile() method
}

public class NestandardniUcetType : UcetType
{
    /// <summary>
    /// Attempting to use this will throw an exception
    /// </summary>
    public override object predcislo
    {
        get { throw new NotSupportedException(); }
        set { throw new NotSupportedException(); }
    }
    /// <summary>
    /// Attempting to use this will throw an exception
    /// </summary>
    public override object kodBanky
    {
        get { throw new NotSupportedException(); }
        set { throw new NotSupportedException(); }
    }

    // change the way WriteToFile behaves
    public override void WriteToFile(StreamWriter file)
    {
        // build the string and write it to the file
        // only considering 'cislo' property
    }
}

// Usage example, based on question
for (int i = 0; i < dic_vystup.Length; i++)
{
    RozhraniWSDL.InformaceOPlatciType info = dic_vystup[i];   

    // I assume "3" is the expected length of the array ? Change the for like this:
    for (int x = 0; x <= info.zverejneneUcty.Length; x++)
    {   
        //Delegate to the WriteToFile() method the task to build and write the line!
        info.zverejneneUcty[x].Item.WriteToFile(file2);
    }
}
最后,一个非常好的方法是为这两种类型编写两个单独的方法,并使用
dynamic
执行分派

  string[] dic_vstup = new string[] { (line) };
            RozhraniWSDL.InformaceOPlatciType[] dic_vystup;
            RozhraniWSDL.rozhraniCRPDPH srv = new RozhraniWSDL.rozhraniCRPDPH();
            StatusType status = srv.getStatusNespolehlivyPlatce(dic_vstup, out dic_vystup);
            string abc = status.bezVypisuUctu.ToString();   // If it is already a string, then ToString not needed


            for (int i = 0; i < dic_vystup.Length; i++)
            {
                RozhraniWSDL.InformaceOPlatciType info = dic_vystup[i];


for (int x = 0; x <= 3; x++)
{   
    file2.WriteLine((((RozhraniWSDL.StandardniUcetType)(info.zverejneneUcty[x].Item)).cislo) + "-"

        + (((RozhraniWSDL.StandardniUcetType)(info.zverejneneUcty[x].Item)).cislo) + "/" 

        + (((RozhraniWSDL.StandardniUcetType)(info.zverejneneUcty[x].Item)).kodBanky));     
}}
if (info.zverejneneUcty[x].Item is RozhraniWSDL.StandardniUcetType) {
    ...
} else {
    ...
}
RozhraniWSDL.StandardniUcetType std = info.zverejneneUcty[x].Item as RozhraniWSDL.StandardniUcetType;
if (std != null) {
    ...
}
RozhraniWSDL.NestandardniUcetType nstd = info.zverejneneUcty[x].Item as RozhraniWSDL.NestandardniUcetType;
if (nstd != null) {
    ...
}
static void WriteToFile(RozhraniWSDL.StandardniUcetType std, StreamWriter file) {
    ...
}
static void WriteToFile(RozhraniWSDL.NestandardniUcetType nstd, StreamWriter file) {
    ...
}
// I'm making up the inner types, adapt this to your code
public abstract class UcetType
{
    public virtual object predcislo { get; set; }
    public virtual object cislo { get; set; }
    public virtual object kodBanky { get; set; }

    public virtual void WriteToFile(StreamWriter file) 
    { 
        // build the string and write it to the file
        // considering all properties
        // this acts as "default" for this type and all derived ones
    }
}

public class StandardniUcetType : UcetType
{
    // This will use the abstract as-is
    // with all 3 properties and the "default" WriteToFile() method
}

public class NestandardniUcetType : UcetType
{
    /// <summary>
    /// Attempting to use this will throw an exception
    /// </summary>
    public override object predcislo
    {
        get { throw new NotSupportedException(); }
        set { throw new NotSupportedException(); }
    }
    /// <summary>
    /// Attempting to use this will throw an exception
    /// </summary>
    public override object kodBanky
    {
        get { throw new NotSupportedException(); }
        set { throw new NotSupportedException(); }
    }

    // change the way WriteToFile behaves
    public override void WriteToFile(StreamWriter file)
    {
        // build the string and write it to the file
        // only considering 'cislo' property
    }
}

// Usage example, based on question
for (int i = 0; i < dic_vystup.Length; i++)
{
    RozhraniWSDL.InformaceOPlatciType info = dic_vystup[i];   

    // I assume "3" is the expected length of the array ? Change the for like this:
    for (int x = 0; x <= info.zverejneneUcty.Length; x++)
    {   
        //Delegate to the WriteToFile() method the task to build and write the line!
        info.zverejneneUcty[x].Item.WriteToFile(file2);
    }
}
现在按如下方式更改循环:

for (int x = 0; x <= 3; x++) {
    dynamic item = info.zverejneneUcty[x].Item;
    WriteToFile(item, file2); // <<== Magic
}

for(int x=0;x我会重新设计类型,并通过一个抽象类来解决这个问题,如下所示:

  string[] dic_vstup = new string[] { (line) };
            RozhraniWSDL.InformaceOPlatciType[] dic_vystup;
            RozhraniWSDL.rozhraniCRPDPH srv = new RozhraniWSDL.rozhraniCRPDPH();
            StatusType status = srv.getStatusNespolehlivyPlatce(dic_vstup, out dic_vystup);
            string abc = status.bezVypisuUctu.ToString();   // If it is already a string, then ToString not needed


            for (int i = 0; i < dic_vystup.Length; i++)
            {
                RozhraniWSDL.InformaceOPlatciType info = dic_vystup[i];


for (int x = 0; x <= 3; x++)
{   
    file2.WriteLine((((RozhraniWSDL.StandardniUcetType)(info.zverejneneUcty[x].Item)).cislo) + "-"

        + (((RozhraniWSDL.StandardniUcetType)(info.zverejneneUcty[x].Item)).cislo) + "/" 

        + (((RozhraniWSDL.StandardniUcetType)(info.zverejneneUcty[x].Item)).kodBanky));     
}}
if (info.zverejneneUcty[x].Item is RozhraniWSDL.StandardniUcetType) {
    ...
} else {
    ...
}
RozhraniWSDL.StandardniUcetType std = info.zverejneneUcty[x].Item as RozhraniWSDL.StandardniUcetType;
if (std != null) {
    ...
}
RozhraniWSDL.NestandardniUcetType nstd = info.zverejneneUcty[x].Item as RozhraniWSDL.NestandardniUcetType;
if (nstd != null) {
    ...
}
static void WriteToFile(RozhraniWSDL.StandardniUcetType std, StreamWriter file) {
    ...
}
static void WriteToFile(RozhraniWSDL.NestandardniUcetType nstd, StreamWriter file) {
    ...
}
// I'm making up the inner types, adapt this to your code
public abstract class UcetType
{
    public virtual object predcislo { get; set; }
    public virtual object cislo { get; set; }
    public virtual object kodBanky { get; set; }

    public virtual void WriteToFile(StreamWriter file) 
    { 
        // build the string and write it to the file
        // considering all properties
        // this acts as "default" for this type and all derived ones
    }
}

public class StandardniUcetType : UcetType
{
    // This will use the abstract as-is
    // with all 3 properties and the "default" WriteToFile() method
}

public class NestandardniUcetType : UcetType
{
    /// <summary>
    /// Attempting to use this will throw an exception
    /// </summary>
    public override object predcislo
    {
        get { throw new NotSupportedException(); }
        set { throw new NotSupportedException(); }
    }
    /// <summary>
    /// Attempting to use this will throw an exception
    /// </summary>
    public override object kodBanky
    {
        get { throw new NotSupportedException(); }
        set { throw new NotSupportedException(); }
    }

    // change the way WriteToFile behaves
    public override void WriteToFile(StreamWriter file)
    {
        // build the string and write it to the file
        // only considering 'cislo' property
    }
}

// Usage example, based on question
for (int i = 0; i < dic_vystup.Length; i++)
{
    RozhraniWSDL.InformaceOPlatciType info = dic_vystup[i];   

    // I assume "3" is the expected length of the array ? Change the for like this:
    for (int x = 0; x <= info.zverejneneUcty.Length; x++)
    {   
        //Delegate to the WriteToFile() method the task to build and write the line!
        info.zverejneneUcty[x].Item.WriteToFile(file2);
    }
}
//我正在编写内部类型,请根据您的代码调整它
公共抽象类UcetType
{
公共虚拟对象predcislo{get;set;}
公共虚拟对象cislo{get;set;}
公共虚拟对象kodBanky{get;set;}
公共虚拟void WriteToFile(StreamWriter文件)
{ 
//构建字符串并将其写入文件
//考虑到所有属性
//这将作为此类型和所有派生类型的“默认值”
}
}
公共类标准类型:UcetType
{
//这将按原样使用摘要
//使用所有3个属性和“默认”WriteToFile()方法
}
公共类嵌套标准类型:UcetType
{
/// 
///尝试使用此选项将引发异常
/// 
公共覆盖对象predcislo
{
获取{抛出新的NotSupportedException();}
设置{抛出新的NotSupportedException();}
}
/// 
///尝试使用此选项将引发异常
/// 
公共覆盖对象库
{
获取{抛出新的NotSupportedException();}
设置{抛出新的NotSupportedException();}
}
//更改WriteToFile的行为方式
公共覆盖无效写入文件(StreamWriter文件)
{
//构建字符串并将其写入文件
//仅考虑“西斯洛”财产
}
}
//基于问题的用法示例
对于(int i=0;i对于(intx=0;x,我会重新设计类型,并通过一个抽象类来解决这个问题,如下所示:

  string[] dic_vstup = new string[] { (line) };
            RozhraniWSDL.InformaceOPlatciType[] dic_vystup;
            RozhraniWSDL.rozhraniCRPDPH srv = new RozhraniWSDL.rozhraniCRPDPH();
            StatusType status = srv.getStatusNespolehlivyPlatce(dic_vstup, out dic_vystup);
            string abc = status.bezVypisuUctu.ToString();   // If it is already a string, then ToString not needed


            for (int i = 0; i < dic_vystup.Length; i++)
            {
                RozhraniWSDL.InformaceOPlatciType info = dic_vystup[i];


for (int x = 0; x <= 3; x++)
{   
    file2.WriteLine((((RozhraniWSDL.StandardniUcetType)(info.zverejneneUcty[x].Item)).cislo) + "-"

        + (((RozhraniWSDL.StandardniUcetType)(info.zverejneneUcty[x].Item)).cislo) + "/" 

        + (((RozhraniWSDL.StandardniUcetType)(info.zverejneneUcty[x].Item)).kodBanky));     
}}
if (info.zverejneneUcty[x].Item is RozhraniWSDL.StandardniUcetType) {
    ...
} else {
    ...
}
RozhraniWSDL.StandardniUcetType std = info.zverejneneUcty[x].Item as RozhraniWSDL.StandardniUcetType;
if (std != null) {
    ...
}
RozhraniWSDL.NestandardniUcetType nstd = info.zverejneneUcty[x].Item as RozhraniWSDL.NestandardniUcetType;
if (nstd != null) {
    ...
}
static void WriteToFile(RozhraniWSDL.StandardniUcetType std, StreamWriter file) {
    ...
}
static void WriteToFile(RozhraniWSDL.NestandardniUcetType nstd, StreamWriter file) {
    ...
}
// I'm making up the inner types, adapt this to your code
public abstract class UcetType
{
    public virtual object predcislo { get; set; }
    public virtual object cislo { get; set; }
    public virtual object kodBanky { get; set; }

    public virtual void WriteToFile(StreamWriter file) 
    { 
        // build the string and write it to the file
        // considering all properties
        // this acts as "default" for this type and all derived ones
    }
}

public class StandardniUcetType : UcetType
{
    // This will use the abstract as-is
    // with all 3 properties and the "default" WriteToFile() method
}

public class NestandardniUcetType : UcetType
{
    /// <summary>
    /// Attempting to use this will throw an exception
    /// </summary>
    public override object predcislo
    {
        get { throw new NotSupportedException(); }
        set { throw new NotSupportedException(); }
    }
    /// <summary>
    /// Attempting to use this will throw an exception
    /// </summary>
    public override object kodBanky
    {
        get { throw new NotSupportedException(); }
        set { throw new NotSupportedException(); }
    }

    // change the way WriteToFile behaves
    public override void WriteToFile(StreamWriter file)
    {
        // build the string and write it to the file
        // only considering 'cislo' property
    }
}

// Usage example, based on question
for (int i = 0; i < dic_vystup.Length; i++)
{
    RozhraniWSDL.InformaceOPlatciType info = dic_vystup[i];   

    // I assume "3" is the expected length of the array ? Change the for like this:
    for (int x = 0; x <= info.zverejneneUcty.Length; x++)
    {   
        //Delegate to the WriteToFile() method the task to build and write the line!
        info.zverejneneUcty[x].Item.WriteToFile(file2);
    }
}
//我正在编写内部类型,请根据您的代码调整它
公共抽象类UcetType
{
公共虚拟对象predcislo{get;set;}
公共虚拟对象cislo{get;set;}
公共虚拟对象kodBanky{get;set;}
公共虚拟void WriteToFile(StreamWriter文件)
{ 
//构建字符串并将其写入文件
//考虑到所有属性
//这将作为此类型和所有派生类型的“默认值”
}
}
公共类标准类型:UcetType
{
//这将按原样使用摘要
//使用所有3个属性和“默认”WriteToFile()方法
}
公共类嵌套标准类型:UcetType
{
/// 
///尝试使用此选项将引发异常
/// 
公共覆盖对象predcislo
{
获取{抛出新的NotSupportedException();}
设置{抛出新的NotSupportedException();}
}
/// 
///尝试使用此选项将引发异常
/// 
公共覆盖对象库
{
获取{抛出新的NotSupportedException();}
设置{抛出新的NotSupportedException();}
}
//更改WriteToFile的行为方式
公共覆盖无效写入文件(StreamWriter文件)
{
//构建字符串并将其写入文件
//仅考虑“西斯洛”财产
}
}
//基于问题的用法示例
对于(int i=0;i这两种类型的(int x=0;x Post(大纲)和数组声明。Post(大纲)两种类型和数组声明中的一种。你的知识让我印象深刻。这对我很有帮助,谢谢。请问是否有办法确定数组包含多少项?我需要更改x我对你的知识印象深刻。这对我很有帮助,谢谢。我可以问一下是否有